{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":5960502,"sourceType":"datasetVersion","datasetId":3418322},{"sourceId":7016744,"sourceType":"datasetVersion","datasetId":4034354},{"sourceId":6017451,"sourceType":"datasetVersion","datasetId":3444172},{"sourceId":8760277,"sourceType":"datasetVersion","datasetId":4299235}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install neurokit2","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:15.448355Z","iopub.execute_input":"2024-06-22T17:15:15.448717Z","iopub.status.idle":"2024-06-22T17:15:27.080031Z","shell.execute_reply.started":"2024-06-22T17:15:15.448688Z","shell.execute_reply":"2024-06-22T17:15:27.078514Z"},"trusted":true},"execution_count":13,"outputs":[{"name":"stdout","text":"Requirement already satisfied: neurokit2 in /opt/conda/lib/python3.10/site-packages (0.2.9)\nRequirement already satisfied: requests in /opt/conda/lib/python3.10/site-packages (from neurokit2) (2.31.0)\nRequirement already satisfied: numpy in /opt/conda/lib/python3.10/site-packages (from neurokit2) (1.24.3)\nRequirement already satisfied: pandas in /opt/conda/lib/python3.10/site-packages (from neurokit2) (2.0.3)\nRequirement already satisfied: scipy in /opt/conda/lib/python3.10/site-packages (from neurokit2) (1.11.4)\nRequirement already satisfied: scikit-learn>=1.0.0 in /opt/conda/lib/python3.10/site-packages (from neurokit2) (1.2.2)\nRequirement already satisfied: matplotlib in /opt/conda/lib/python3.10/site-packages (from neurokit2) (3.7.4)\nRequirement already satisfied: joblib>=1.1.1 in /opt/conda/lib/python3.10/site-packages (from scikit-learn>=1.0.0->neurokit2) (1.3.2)\nRequirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from scikit-learn>=1.0.0->neurokit2) (3.2.0)\nRequirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (1.1.0)\nRequirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (0.11.0)\nRequirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (4.42.1)\nRequirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (1.4.4)\nRequirement already satisfied: packaging>=20.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (21.3)\nRequirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (10.1.0)\nRequirement already satisfied: pyparsing>=2.3.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (3.0.9)\nRequirement already satisfied: python-dateutil>=2.7 in /opt/conda/lib/python3.10/site-packages (from matplotlib->neurokit2) (2.8.2)\nRequirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas->neurokit2) (2023.3)\nRequirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.10/site-packages (from pandas->neurokit2) (2023.3)\nRequirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests->neurokit2) (3.2.0)\nRequirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests->neurokit2) (3.4)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests->neurokit2) (1.26.15)\nRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests->neurokit2) (2023.11.17)\nRequirement already satisfied: six>=1.5 in /opt/conda/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib->neurokit2) (1.16.0)\n\u001b[33mWARNING: Error parsing requirements for pexpect: [Errno 2] No such file or directory: '/opt/conda/lib/python3.10/site-packages/pexpect-4.8.0.dist-info/METADATA'\u001b[0m\u001b[33m\n\u001b[0m","output_type":"stream"}]},{"cell_type":"code","source":"!pip install hrv-analysis\n!pip install pyhrv","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:27.086030Z","iopub.execute_input":"2024-06-22T17:15:27.086444Z","iopub.status.idle":"2024-06-22T17:15:50.217253Z","shell.execute_reply.started":"2024-06-22T17:15:27.086405Z","shell.execute_reply":"2024-06-22T17:15:50.216222Z"},"trusted":true},"execution_count":14,"outputs":[{"name":"stdout","text":"Requirement already satisfied: hrv-analysis in /opt/conda/lib/python3.10/site-packages (1.0.4)\nRequirement already satisfied: numpy>=1.15.1 in /opt/conda/lib/python3.10/site-packages (from hrv-analysis) (1.24.3)\nRequirement already satisfied: astropy>=3.0.4 in /opt/conda/lib/python3.10/site-packages (from hrv-analysis) (6.0.0)\nRequirement already satisfied: nolds>=0.4.1 in /opt/conda/lib/python3.10/site-packages (from hrv-analysis) (0.5.2)\nRequirement already satisfied: scipy>=1.1.0 in /opt/conda/lib/python3.10/site-packages (from hrv-analysis) (1.11.4)\nRequirement already satisfied: pandas>=0.23.4 in /opt/conda/lib/python3.10/site-packages (from hrv-analysis) (2.0.3)\nRequirement already satisfied: matplotlib>=2.2.2 in /opt/conda/lib/python3.10/site-packages (from hrv-analysis) (3.7.4)\nRequirement already satisfied: pyerfa>=2.0 in /opt/conda/lib/python3.10/site-packages (from astropy>=3.0.4->hrv-analysis) (2.0.1.1)\nRequirement already satisfied: astropy-iers-data>=0.2023.10.30.0.29.53 in /opt/conda/lib/python3.10/site-packages (from astropy>=3.0.4->hrv-analysis) (0.2023.12.11.0.31.11)\nRequirement already satisfied: PyYAML>=3.13 in /opt/conda/lib/python3.10/site-packages (from astropy>=3.0.4->hrv-analysis) (6.0.1)\nRequirement already satisfied: packaging>=19.0 in /opt/conda/lib/python3.10/site-packages (from astropy>=3.0.4->hrv-analysis) (21.3)\nRequirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (1.1.0)\nRequirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (0.11.0)\nRequirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (4.42.1)\nRequirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (1.4.4)\nRequirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (10.1.0)\nRequirement already satisfied: pyparsing>=2.3.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (3.0.9)\nRequirement already satisfied: python-dateutil>=2.7 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=2.2.2->hrv-analysis) (2.8.2)\nRequirement already satisfied: future in /opt/conda/lib/python3.10/site-packages (from nolds>=0.4.1->hrv-analysis) (0.18.3)\nRequirement already satisfied: setuptools in /opt/conda/lib/python3.10/site-packages (from nolds>=0.4.1->hrv-analysis) (68.1.2)\nRequirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.23.4->hrv-analysis) (2023.3)\nRequirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.23.4->hrv-analysis) (2023.3)\nRequirement already satisfied: six>=1.5 in /opt/conda/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=2.2.2->hrv-analysis) (1.16.0)\n\u001b[33mWARNING: Error parsing requirements for pexpect: [Errno 2] No such file or directory: '/opt/conda/lib/python3.10/site-packages/pexpect-4.8.0.dist-info/METADATA'\u001b[0m\u001b[33m\n\u001b[0mRequirement already satisfied: pyhrv in /opt/conda/lib/python3.10/site-packages (0.4.1)\nRequirement already satisfied: biosppy in /opt/conda/lib/python3.10/site-packages (from pyhrv) (2.2.2)\nRequirement already satisfied: matplotlib in /opt/conda/lib/python3.10/site-packages (from pyhrv) (3.7.4)\nRequirement already satisfied: numpy in /opt/conda/lib/python3.10/site-packages (from pyhrv) (1.24.3)\nRequirement already satisfied: scipy in /opt/conda/lib/python3.10/site-packages (from pyhrv) (1.11.4)\nRequirement already satisfied: nolds in /opt/conda/lib/python3.10/site-packages (from pyhrv) (0.5.2)\nRequirement already satisfied: spectrum in /opt/conda/lib/python3.10/site-packages (from pyhrv) (0.8.1)\nRequirement already satisfied: bidict in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (0.22.1)\nRequirement already satisfied: h5py in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (3.9.0)\nRequirement already satisfied: scikit-learn in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (1.2.2)\nRequirement already satisfied: shortuuid in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (1.0.13)\nRequirement already satisfied: six in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (1.16.0)\nRequirement already satisfied: joblib in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (1.3.2)\nRequirement already satisfied: opencv-python in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (4.8.1.78)\nRequirement already satisfied: pywavelets in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (1.4.1)\nRequirement already satisfied: mock in /opt/conda/lib/python3.10/site-packages (from biosppy->pyhrv) (5.1.0)\nRequirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (1.1.0)\nRequirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (0.11.0)\nRequirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (4.42.1)\nRequirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (1.4.4)\nRequirement already satisfied: packaging>=20.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (21.3)\nRequirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (10.1.0)\nRequirement already satisfied: pyparsing>=2.3.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (3.0.9)\nRequirement already satisfied: python-dateutil>=2.7 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pyhrv) (2.8.2)\nRequirement already satisfied: future in /opt/conda/lib/python3.10/site-packages (from nolds->pyhrv) (0.18.3)\nRequirement already satisfied: setuptools in /opt/conda/lib/python3.10/site-packages (from nolds->pyhrv) (68.1.2)\nRequirement already satisfied: easydev in /opt/conda/lib/python3.10/site-packages (from spectrum->pyhrv) (0.13.2)\nRequirement already satisfied: colorama<0.5.0,>=0.4.6 in /opt/conda/lib/python3.10/site-packages (from easydev->spectrum->pyhrv) (0.4.6)\nRequirement already satisfied: colorlog<7.0.0,>=6.8.2 in /opt/conda/lib/python3.10/site-packages (from easydev->spectrum->pyhrv) (6.8.2)\nRequirement already satisfied: line-profiler<5.0.0,>=4.1.2 in /opt/conda/lib/python3.10/site-packages (from easydev->spectrum->pyhrv) (4.1.2)\nCollecting pexpect<5.0.0,>=4.9.0 (from easydev->spectrum->pyhrv)\n  Obtaining dependency information for pexpect<5.0.0,>=4.9.0 from https://files.pythonhosted.org/packages/9e/c3/059298687310d527a58bb01f3b1965787ee3b40dce76752eda8b44e9a2c5/pexpect-4.9.0-py2.py3-none-any.whl.metadata\n  Using cached pexpect-4.9.0-py2.py3-none-any.whl.metadata (2.5 kB)\nRequirement already satisfied: platformdirs<5.0.0,>=4.2.0 in /opt/conda/lib/python3.10/site-packages (from easydev->spectrum->pyhrv) (4.2.2)\nRequirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from scikit-learn->biosppy->pyhrv) (3.2.0)\nRequirement already satisfied: ptyprocess>=0.5 in /opt/conda/lib/python3.10/site-packages (from pexpect<5.0.0,>=4.9.0->easydev->spectrum->pyhrv) (0.7.0)\nUsing cached pexpect-4.9.0-py2.py3-none-any.whl (63 kB)\n\u001b[33mWARNING: Error parsing requirements for pexpect: [Errno 2] No such file or directory: '/opt/conda/lib/python3.10/site-packages/pexpect-4.8.0.dist-info/METADATA'\u001b[0m\u001b[33m\n\u001b[0mInstalling collected packages: pexpect\n  Attempting uninstall: pexpect\n\u001b[33m    WARNING: No metadata found in /opt/conda/lib/python3.10/site-packages\u001b[0m\u001b[33m\n\u001b[0m    Found existing installation: pexpect 4.8.0\n\u001b[31mERROR: Cannot uninstall pexpect 4.8.0, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps pexpect==4.8.0'.\u001b[0m\u001b[31m\n\u001b[0m","output_type":"stream"}]},{"cell_type":"code","source":"import tensorflow as tf\nfrom matplotlib import pyplot as plt\nimport seaborn as sns\nimport pandas as pd\nimport numpy as np\nimport wfdb\nimport os\nimport ast\nimport neurokit2 as nk\nimport matplotlib\nimport matplotlib.pyplot as plt\npd.options.mode.chained_assignment = None","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-06-22T17:15:50.218704Z","iopub.execute_input":"2024-06-22T17:15:50.219026Z","iopub.status.idle":"2024-06-22T17:15:50.225443Z","shell.execute_reply.started":"2024-06-22T17:15:50.218979Z","shell.execute_reply":"2024-06-22T17:15:50.224296Z"},"trusted":true},"execution_count":15,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)\npd.options.mode.chained_assignment = None","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.228594Z","iopub.execute_input":"2024-06-22T17:15:50.228998Z","iopub.status.idle":"2024-06-22T17:15:50.234497Z","shell.execute_reply.started":"2024-06-22T17:15:50.228964Z","shell.execute_reply":"2024-06-22T17:15:50.233645Z"},"trusted":true},"execution_count":16,"outputs":[]},{"cell_type":"code","source":"import warnings\n#from scipy.interpolate import interp1d\n#from scipy import signal\n#from scipy.integrate import trapz\n#import pyhrv.tools as tools\n#import pyhrv.frequency_domain as fd\n\nwarnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.235481Z","iopub.execute_input":"2024-06-22T17:15:50.235734Z","iopub.status.idle":"2024-06-22T17:15:50.243719Z","shell.execute_reply.started":"2024-06-22T17:15:50.235712Z","shell.execute_reply":"2024-06-22T17:15:50.242848Z"},"trusted":true},"execution_count":17,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/ptb-xl-a-large-publicly-available2/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.3/'\n\necg_data = pd.read_csv(path + 'ptbxl_database.csv', index_col='ecg_id')\nscp_data = pd.read_csv(path + 'scp_statements.csv')","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.244806Z","iopub.execute_input":"2024-06-22T17:15:50.245091Z","iopub.status.idle":"2024-06-22T17:15:50.404593Z","shell.execute_reply.started":"2024-06-22T17:15:50.245068Z","shell.execute_reply":"2024-06-22T17:15:50.403797Z"},"trusted":true},"execution_count":18,"outputs":[]},{"cell_type":"code","source":"ecg_data[:5]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.405798Z","iopub.execute_input":"2024-06-22T17:15:50.406190Z","iopub.status.idle":"2024-06-22T17:15:50.434310Z","shell.execute_reply.started":"2024-06-22T17:15:50.406154Z","shell.execute_reply":"2024-06-22T17:15:50.433163Z"},"trusted":true},"execution_count":19,"outputs":[{"execution_count":19,"output_type":"execute_result","data":{"text/plain":"        patient_id   age  sex  height  weight  nurse  site     device  \\\necg_id                                                                  \n1          15709.0  56.0    1     NaN    63.0    2.0   0.0  CS-12   E   \n2          13243.0  19.0    0     NaN    70.0    2.0   0.0  CS-12   E   \n3          20372.0  37.0    1     NaN    69.0    2.0   0.0  CS-12   E   \n4          17014.0  24.0    0     NaN    82.0    2.0   0.0  CS-12   E   \n5          17448.0  19.0    1     NaN    70.0    2.0   0.0  CS-12   E   \n\n             recording_date                                  report  ...  \\\necg_id                                                               ...   \n1       1984-11-09 09:17:34  sinusrhythmus periphere niederspannung  ...   \n2       1984-11-14 12:55:37     sinusbradykardie sonst normales ekg  ...   \n3       1984-11-15 12:49:10              sinusrhythmus normales ekg  ...   \n4       1984-11-15 13:44:57              sinusrhythmus normales ekg  ...   \n5       1984-11-17 10:43:15              sinusrhythmus normales ekg  ...   \n\n       validated_by_human  baseline_drift static_noise burst_noise  \\\necg_id                                                               \n1                    True             NaN    , I-V1,           NaN   \n2                    True             NaN          NaN         NaN   \n3                    True             NaN          NaN         NaN   \n4                    True    , II,III,AVF          NaN         NaN   \n5                    True   , III,AVR,AVF          NaN         NaN   \n\n        electrodes_problems  extra_beats  pacemaker  strat_fold  \\\necg_id                                                            \n1                       NaN          NaN        NaN           3   \n2                       NaN          NaN        NaN           2   \n3                       NaN          NaN        NaN           5   \n4                       NaN          NaN        NaN           3   \n5                       NaN          NaN        NaN           4   \n\n                      filename_lr                filename_hr  \necg_id                                                        \n1       records100/00000/00001_lr  records500/00000/00001_hr  \n2       records100/00000/00002_lr  records500/00000/00002_hr  \n3       records100/00000/00003_lr  records500/00000/00003_hr  \n4       records100/00000/00004_lr  records500/00000/00004_hr  \n5       records100/00000/00005_lr  records500/00000/00005_hr  \n\n[5 rows x 27 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>height</th>\n      <th>weight</th>\n      <th>nurse</th>\n      <th>site</th>\n      <th>device</th>\n      <th>recording_date</th>\n      <th>report</th>\n      <th>...</th>\n      <th>validated_by_human</th>\n      <th>baseline_drift</th>\n      <th>static_noise</th>\n      <th>burst_noise</th>\n      <th>electrodes_problems</th>\n      <th>extra_beats</th>\n      <th>pacemaker</th>\n      <th>strat_fold</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>15709.0</td>\n      <td>56.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>63.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-09 09:17:34</td>\n      <td>sinusrhythmus periphere niederspannung</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>, I-V1,</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>3</td>\n      <td>records100/00000/00001_lr</td>\n      <td>records500/00000/00001_hr</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>13243.0</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>70.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-14 12:55:37</td>\n      <td>sinusbradykardie sonst normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>2</td>\n      <td>records100/00000/00002_lr</td>\n      <td>records500/00000/00002_hr</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>20372.0</td>\n      <td>37.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>69.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-15 12:49:10</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>5</td>\n      <td>records100/00000/00003_lr</td>\n      <td>records500/00000/00003_hr</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>17014.0</td>\n      <td>24.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>82.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-15 13:44:57</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>, II,III,AVF</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>3</td>\n      <td>records100/00000/00004_lr</td>\n      <td>records500/00000/00004_hr</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>17448.0</td>\n      <td>19.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>70.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-17 10:43:15</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>, III,AVR,AVF</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>4</td>\n      <td>records100/00000/00005_lr</td>\n      <td>records500/00000/00005_hr</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 27 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"scp_data.columns","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.435701Z","iopub.execute_input":"2024-06-22T17:15:50.436102Z","iopub.status.idle":"2024-06-22T17:15:50.442643Z","shell.execute_reply.started":"2024-06-22T17:15:50.436074Z","shell.execute_reply":"2024-06-22T17:15:50.441641Z"},"trusted":true},"execution_count":20,"outputs":[{"execution_count":20,"output_type":"execute_result","data":{"text/plain":"Index(['Unnamed: 0', 'description', 'diagnostic', 'form', 'rhythm',\n       'diagnostic_class', 'diagnostic_subclass', 'Statement Category',\n       'SCP-ECG Statement Description', 'AHA code', 'aECG REFID', 'CDISC Code',\n       'DICOM Code'],\n      dtype='object')"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_new = ecg_data.copy()\nfor i in ['nurse','site','device','recording_date','heart_axis','infarction_stadium1','infarction_stadium2',\n         'validated_by_human','baseline_drift','validated_by','second_opinion','initial_autogenerated_report',\n         'static_noise','burst_noise','extra_beats','strat_fold','pacemaker','height']:\n    del ecg_data_new[i]\n","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.443665Z","iopub.execute_input":"2024-06-22T17:15:50.443942Z","iopub.status.idle":"2024-06-22T17:15:50.458104Z","shell.execute_reply.started":"2024-06-22T17:15:50.443918Z","shell.execute_reply":"2024-06-22T17:15:50.457238Z"},"trusted":true},"execution_count":21,"outputs":[]},{"cell_type":"code","source":"ecg_data_new[:5]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.462624Z","iopub.execute_input":"2024-06-22T17:15:50.463203Z","iopub.status.idle":"2024-06-22T17:15:50.477573Z","shell.execute_reply.started":"2024-06-22T17:15:50.463171Z","shell.execute_reply":"2024-06-22T17:15:50.476348Z"},"trusted":true},"execution_count":22,"outputs":[{"execution_count":22,"output_type":"execute_result","data":{"text/plain":"        patient_id   age  sex  weight                                  report  \\\necg_id                                                                          \n1          15709.0  56.0    1    63.0  sinusrhythmus periphere niederspannung   \n2          13243.0  19.0    0    70.0     sinusbradykardie sonst normales ekg   \n3          20372.0  37.0    1    69.0              sinusrhythmus normales ekg   \n4          17014.0  24.0    0    82.0              sinusrhythmus normales ekg   \n5          17448.0  19.0    1    70.0              sinusrhythmus normales ekg   \n\n                                       scp_codes electrodes_problems  \\\necg_id                                                                 \n1       {'NORM': 100.0, 'LVOLT': 0.0, 'SR': 0.0}                 NaN   \n2                   {'NORM': 80.0, 'SBRAD': 0.0}                 NaN   \n3                     {'NORM': 100.0, 'SR': 0.0}                 NaN   \n4                     {'NORM': 100.0, 'SR': 0.0}                 NaN   \n5                     {'NORM': 100.0, 'SR': 0.0}                 NaN   \n\n                      filename_lr                filename_hr  \necg_id                                                        \n1       records100/00000/00001_lr  records500/00000/00001_hr  \n2       records100/00000/00002_lr  records500/00000/00002_hr  \n3       records100/00000/00003_lr  records500/00000/00003_hr  \n4       records100/00000/00004_lr  records500/00000/00004_hr  \n5       records100/00000/00005_lr  records500/00000/00005_hr  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>weight</th>\n      <th>report</th>\n      <th>scp_codes</th>\n      <th>electrodes_problems</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>15709.0</td>\n      <td>56.0</td>\n      <td>1</td>\n      <td>63.0</td>\n      <td>sinusrhythmus periphere niederspannung</td>\n      <td>{'NORM': 100.0, 'LVOLT': 0.0, 'SR': 0.0}</td>\n      <td>NaN</td>\n      <td>records100/00000/00001_lr</td>\n      <td>records500/00000/00001_hr</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>13243.0</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>70.0</td>\n      <td>sinusbradykardie sonst normales ekg</td>\n      <td>{'NORM': 80.0, 'SBRAD': 0.0}</td>\n      <td>NaN</td>\n      <td>records100/00000/00002_lr</td>\n      <td>records500/00000/00002_hr</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>20372.0</td>\n      <td>37.0</td>\n      <td>1</td>\n      <td>69.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>{'NORM': 100.0, 'SR': 0.0}</td>\n      <td>NaN</td>\n      <td>records100/00000/00003_lr</td>\n      <td>records500/00000/00003_hr</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>17014.0</td>\n      <td>24.0</td>\n      <td>0</td>\n      <td>82.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>{'NORM': 100.0, 'SR': 0.0}</td>\n      <td>NaN</td>\n      <td>records100/00000/00004_lr</td>\n      <td>records500/00000/00004_hr</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>17448.0</td>\n      <td>19.0</td>\n      <td>1</td>\n      <td>70.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>{'NORM': 100.0, 'SR': 0.0}</td>\n      <td>NaN</td>\n      <td>records100/00000/00005_lr</td>\n      <td>records500/00000/00005_hr</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"scp_data[:5]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.478836Z","iopub.execute_input":"2024-06-22T17:15:50.479193Z","iopub.status.idle":"2024-06-22T17:15:50.496558Z","shell.execute_reply.started":"2024-06-22T17:15:50.479159Z","shell.execute_reply":"2024-06-22T17:15:50.495572Z"},"trusted":true},"execution_count":23,"outputs":[{"execution_count":23,"output_type":"execute_result","data":{"text/plain":"  Unnamed: 0                     description  diagnostic  form  rhythm  \\\n0        NDT  non-diagnostic T abnormalities         1.0   1.0     NaN   \n1       NST_         non-specific ST changes         1.0   1.0     NaN   \n2        DIG                digitalis-effect         1.0   1.0     NaN   \n3      LNGQT                long QT-interval         1.0   1.0     NaN   \n4       NORM                      normal ECG         1.0   NaN     NaN   \n\n  diagnostic_class diagnostic_subclass  \\\n0             STTC                STTC   \n1             STTC                NST_   \n2             STTC                STTC   \n3             STTC                STTC   \n4             NORM                NORM   \n\n                                  Statement Category  \\\n0                  other ST-T descriptive statements   \n1  Basic roots for coding ST-T changes and abnorm...   \n2                  other ST-T descriptive statements   \n3                  other ST-T descriptive statements   \n4                                    Normal/abnormal   \n\n    SCP-ECG Statement Description  AHA code            aECG REFID CDISC Code  \\\n0  non-diagnostic T abnormalities       NaN                   NaN        NaN   \n1         non-specific ST changes     145.0  MDC_ECG_RHY_STHILOST        NaN   \n2       suggests digitalis-effect     205.0                   NaN        NaN   \n3                long QT-interval     148.0                   NaN        NaN   \n4                      normal ECG       1.0                   NaN        NaN   \n\n  DICOM Code  \n0        NaN  \n1        NaN  \n2        NaN  \n3        NaN  \n4    F-000B7  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>description</th>\n      <th>diagnostic</th>\n      <th>form</th>\n      <th>rhythm</th>\n      <th>diagnostic_class</th>\n      <th>diagnostic_subclass</th>\n      <th>Statement Category</th>\n      <th>SCP-ECG Statement Description</th>\n      <th>AHA code</th>\n      <th>aECG REFID</th>\n      <th>CDISC Code</th>\n      <th>DICOM Code</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>NDT</td>\n      <td>non-diagnostic T abnormalities</td>\n      <td>1.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>STTC</td>\n      <td>STTC</td>\n      <td>other ST-T descriptive statements</td>\n      <td>non-diagnostic T abnormalities</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>NST_</td>\n      <td>non-specific ST changes</td>\n      <td>1.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>STTC</td>\n      <td>NST_</td>\n      <td>Basic roots for coding ST-T changes and abnorm...</td>\n      <td>non-specific ST changes</td>\n      <td>145.0</td>\n      <td>MDC_ECG_RHY_STHILOST</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>DIG</td>\n      <td>digitalis-effect</td>\n      <td>1.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>STTC</td>\n      <td>STTC</td>\n      <td>other ST-T descriptive statements</td>\n      <td>suggests digitalis-effect</td>\n      <td>205.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>LNGQT</td>\n      <td>long QT-interval</td>\n      <td>1.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>STTC</td>\n      <td>STTC</td>\n      <td>other ST-T descriptive statements</td>\n      <td>long QT-interval</td>\n      <td>148.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>NORM</td>\n      <td>normal ECG</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NORM</td>\n      <td>NORM</td>\n      <td>Normal/abnormal</td>\n      <td>normal ECG</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>F-000B7</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"scp_data[(scp_data[\"rhythm\"] ==1) & (scp_data[\"AHA code\"] > 0)]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.497841Z","iopub.execute_input":"2024-06-22T17:15:50.498454Z","iopub.status.idle":"2024-06-22T17:15:50.517628Z","shell.execute_reply.started":"2024-06-22T17:15:50.498403Z","shell.execute_reply":"2024-06-22T17:15:50.516721Z"},"trusted":true},"execution_count":24,"outputs":[{"execution_count":24,"output_type":"execute_result","data":{"text/plain":"   Unnamed: 0                   description  diagnostic  form  rhythm  \\\n59         SR                  sinus rhythm         NaN   NaN     1.0   \n60       AFIB           atrial fibrillation         NaN   NaN     1.0   \n61      STACH             sinus tachycardia         NaN   NaN     1.0   \n62      SARRH              sinus arrhythmia         NaN   NaN     1.0   \n63      SBRAD             sinus bradycardia         NaN   NaN     1.0   \n67       AFLT                atrial flutter         NaN   NaN     1.0   \n68      SVTAC  supraventricular tachycardia         NaN   NaN     1.0   \n\n   diagnostic_class diagnostic_subclass  \\\n59              NaN                 NaN   \n60              NaN                 NaN   \n61              NaN                 NaN   \n62              NaN                 NaN   \n63              NaN                 NaN   \n67              NaN                 NaN   \n68              NaN                 NaN   \n\n                                   Statement Category  \\\n59  Statements related to impulse formation (abnor...   \n60  Statements related to impulse formation (abnor...   \n61  Statements related to impulse formation (abnor...   \n62  Statements related to impulse formation (abnor...   \n63  Statements related to impulse formation (abnor...   \n67  Statements related to impulse formation (abnor...   \n68  Statements related to impulse formation (abnor...   \n\n   SCP-ECG Statement Description  AHA code               aECG REFID  \\\n59                  sinus rhythm      20.0    MDC_ECG_RHY_SINUS_RHY   \n60           atrial fibrillation      50.0      MDC_ECG_RHY_ATR_FIB   \n61             sinus tachycardia      21.0  MDC_ECG_RHY_SINUS_TACHY   \n62              sinus arrhythmia      23.0  MDC_ECG_RHY_SINUS_ARRHY   \n63             sinus bradycardia      22.0  MDC_ECG_RHY_SINUS_BRADY   \n67                atrial flutter      51.0     MDC_ECG_RHY_ATR_FLUT   \n68  supraventricular tachycardia      55.0     MDC_ECG_RHY_SV_TACHY   \n\n   CDISC Code DICOM Code  \n59        NaN        NaN  \n60        NaN   D3-31520  \n61        NaN        NaN  \n62        NaN        NaN  \n63        NaN        NaN  \n67        NaN        NaN  \n68        NaN   D3-31290  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>description</th>\n      <th>diagnostic</th>\n      <th>form</th>\n      <th>rhythm</th>\n      <th>diagnostic_class</th>\n      <th>diagnostic_subclass</th>\n      <th>Statement Category</th>\n      <th>SCP-ECG Statement Description</th>\n      <th>AHA code</th>\n      <th>aECG REFID</th>\n      <th>CDISC Code</th>\n      <th>DICOM Code</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>59</th>\n      <td>SR</td>\n      <td>sinus rhythm</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>sinus rhythm</td>\n      <td>20.0</td>\n      <td>MDC_ECG_RHY_SINUS_RHY</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>60</th>\n      <td>AFIB</td>\n      <td>atrial fibrillation</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>atrial fibrillation</td>\n      <td>50.0</td>\n      <td>MDC_ECG_RHY_ATR_FIB</td>\n      <td>NaN</td>\n      <td>D3-31520</td>\n    </tr>\n    <tr>\n      <th>61</th>\n      <td>STACH</td>\n      <td>sinus tachycardia</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>sinus tachycardia</td>\n      <td>21.0</td>\n      <td>MDC_ECG_RHY_SINUS_TACHY</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>62</th>\n      <td>SARRH</td>\n      <td>sinus arrhythmia</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>sinus arrhythmia</td>\n      <td>23.0</td>\n      <td>MDC_ECG_RHY_SINUS_ARRHY</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>63</th>\n      <td>SBRAD</td>\n      <td>sinus bradycardia</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>sinus bradycardia</td>\n      <td>22.0</td>\n      <td>MDC_ECG_RHY_SINUS_BRADY</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>67</th>\n      <td>AFLT</td>\n      <td>atrial flutter</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>atrial flutter</td>\n      <td>51.0</td>\n      <td>MDC_ECG_RHY_ATR_FLUT</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>68</th>\n      <td>SVTAC</td>\n      <td>supraventricular tachycardia</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>Statements related to impulse formation (abnor...</td>\n      <td>supraventricular tachycardia</td>\n      <td>55.0</td>\n      <td>MDC_ECG_RHY_SV_TACHY</td>\n      <td>NaN</td>\n      <td>D3-31290</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"def del_symbol_l_1(ecg_data_new_del):\n    for i in ecg_data_new_del.index:\n        str_0 = ecg_data_new_del.scp_codes[i][1:-1] + ','\n        str_0 = str_0.replace(\"'\", \"\")\n        ecg_data_new_del.scp_codes[i] = str_0\n    return ecg_data_new_del\necg_data_new  = del_symbol_l_1(ecg_data_new)\necg_data_new[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:50.518670Z","iopub.execute_input":"2024-06-22T17:15:50.519074Z","iopub.status.idle":"2024-06-22T17:15:55.503603Z","shell.execute_reply.started":"2024-06-22T17:15:50.518997Z","shell.execute_reply":"2024-06-22T17:15:55.502626Z"},"trusted":true},"execution_count":25,"outputs":[{"execution_count":25,"output_type":"execute_result","data":{"text/plain":"        patient_id   age  sex  weight                                  report  \\\necg_id                                                                          \n1          15709.0  56.0    1    63.0  sinusrhythmus periphere niederspannung   \n2          13243.0  19.0    0    70.0     sinusbradykardie sonst normales ekg   \n\n                                scp_codes electrodes_problems  \\\necg_id                                                          \n1       NORM: 100.0, LVOLT: 0.0, SR: 0.0,                 NaN   \n2                 NORM: 80.0, SBRAD: 0.0,                 NaN   \n\n                      filename_lr                filename_hr  \necg_id                                                        \n1       records100/00000/00001_lr  records500/00000/00001_hr  \n2       records100/00000/00002_lr  records500/00000/00002_hr  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>weight</th>\n      <th>report</th>\n      <th>scp_codes</th>\n      <th>electrodes_problems</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>15709.0</td>\n      <td>56.0</td>\n      <td>1</td>\n      <td>63.0</td>\n      <td>sinusrhythmus periphere niederspannung</td>\n      <td>NORM: 100.0, LVOLT: 0.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00001_lr</td>\n      <td>records500/00000/00001_hr</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>13243.0</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>70.0</td>\n      <td>sinusbradykardie sonst normales ekg</td>\n      <td>NORM: 80.0, SBRAD: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00002_lr</td>\n      <td>records500/00000/00002_hr</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"markdown","source":"## Выделяем нарушения ритма","metadata":{}},{"cell_type":"code","source":"def del_symbol_l_2_2(ecg_data_new_del,scp_data_n,name1,name2):\n    list1=[]\n    list2=[]\n    for i in ecg_data_new_del.index:\n        str_0 = \"\"\n        rhythm_number=\"\"\n        for j in ecg_data_new_del.scp_codes[i].split(\",\"):\n            if  j.split(\":\")[0] in list(scp_data_n[\"Unnamed: 0\"]) :\n                str_0= str_0+ j.split(\":\")[0] +\",\"\n                rhythm_number= rhythm_number+ j.split(\":\")[1] +\",\"\n            if  j.split(\":\")[0][1:] in list(scp_data_n[\"Unnamed: 0\"]):\n                j = j[1:]\n                str_0= str_0+ j.split(\":\")[0] +\",\"\n                rhythm_number= rhythm_number+ j.split(\":\")[1] +\",\"\n        \n        list1.append(str_0[:-1])\n        list2.append(rhythm_number[:-1])\n    ecg_data_new_del[name1] = list1\n    ecg_data_new_del[name2] = list2\n    return ecg_data_new_del","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:55.504728Z","iopub.execute_input":"2024-06-22T17:15:55.504993Z","iopub.status.idle":"2024-06-22T17:15:55.513026Z","shell.execute_reply.started":"2024-06-22T17:15:55.504970Z","shell.execute_reply":"2024-06-22T17:15:55.511993Z"},"trusted":true},"execution_count":26,"outputs":[]},{"cell_type":"code","source":"scp_data_n = scp_data[(scp_data[\"rhythm\"] ==1) & (scp_data[\"AHA code\"] > 0)]\necg_data_new = del_symbol_l_2_2(ecg_data_new,scp_data_n,\"rhythm\",\"rhythm_number\")","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:55.514164Z","iopub.execute_input":"2024-06-22T17:15:55.514438Z","iopub.status.idle":"2024-06-22T17:15:57.561070Z","shell.execute_reply.started":"2024-06-22T17:15:55.514414Z","shell.execute_reply":"2024-06-22T17:15:57.560221Z"},"trusted":true},"execution_count":27,"outputs":[]},{"cell_type":"code","source":"ecg_data_new.rhythm.value_counts()#.plot(kind='bar');","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:57.562085Z","iopub.execute_input":"2024-06-22T17:15:57.562370Z","iopub.status.idle":"2024-06-22T17:15:57.573881Z","shell.execute_reply.started":"2024-06-22T17:15:57.562345Z","shell.execute_reply":"2024-06-22T17:15:57.572983Z"},"trusted":true},"execution_count":28,"outputs":[{"execution_count":28,"output_type":"execute_result","data":{"text/plain":"rhythm\nSR             16739\nAFIB            1496\n                1243\nSTACH            821\nSARRH            767\nSBRAD            634\nAFLT              40\nSVTAC             18\nAFLT,AFIB         15\nAFLT,SVTAC         6\nAFLT,STACH         5\nSBRAD,SARRH        3\nAFLT,SR            3\nSR,AFLT            2\nAFIB,AFLT          2\nSR,SARRH           2\nSVTAC,AFIB         1\nSR,SVTAC           1\nSVTAC,SR           1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_new.rhythm.value_counts().index[:8]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:57.574956Z","iopub.execute_input":"2024-06-22T17:15:57.575437Z","iopub.status.idle":"2024-06-22T17:15:57.585972Z","shell.execute_reply.started":"2024-06-22T17:15:57.575412Z","shell.execute_reply":"2024-06-22T17:15:57.585031Z"},"trusted":true},"execution_count":29,"outputs":[{"execution_count":29,"output_type":"execute_result","data":{"text/plain":"Index(['SR', 'AFIB', '', 'STACH', 'SARRH', 'SBRAD', 'AFLT', 'SVTAC'], dtype='object', name='rhythm')"},"metadata":{}}]},{"cell_type":"code","source":"for i in ecg_data_new.index:\n    if (ecg_data_new.rhythm[i] in ecg_data_new.rhythm.value_counts().index[:8]) != True:\n        ecg_data_new = ecg_data_new.drop(index=[i])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:15:57.587068Z","iopub.execute_input":"2024-06-22T17:15:57.587351Z","iopub.status.idle":"2024-06-22T17:17:12.514809Z","shell.execute_reply.started":"2024-06-22T17:15:57.587328Z","shell.execute_reply":"2024-06-22T17:17:12.514063Z"},"trusted":true},"execution_count":30,"outputs":[]},{"cell_type":"code","source":"ecg_data_new.rhythm.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:17:12.515954Z","iopub.execute_input":"2024-06-22T17:17:12.516257Z","iopub.status.idle":"2024-06-22T17:17:12.526737Z","shell.execute_reply.started":"2024-06-22T17:17:12.516231Z","shell.execute_reply":"2024-06-22T17:17:12.525704Z"},"trusted":true},"execution_count":31,"outputs":[{"execution_count":31,"output_type":"execute_result","data":{"text/plain":"rhythm\nSR       16739\nAFIB      1496\n          1243\nSTACH      821\nSARRH      767\nSBRAD      634\nAFLT        40\nSVTAC       18\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"markdown","source":"В основном выделен:\n1. SR -  синусовый ритм \n2. AFIB - atrial fibrillation,\n3. [] - не заполненно? \n4. STACH - sinus tachycardia\n5. SARRH - sinus arrhythmia\n6. SBRAD - sinus bradycardia\n7. AFLT(40) - atrial flutter\n8. SVTAC(18) - supraventricular tachycardia\n\nНе имеет смысла рассматривать двойные дагнозы ритма","metadata":{}},{"cell_type":"markdown","source":"## Выделяем нарушения диагноза","metadata":{}},{"cell_type":"code","source":"ecg_data_new_12  = del_symbol_l_2_2(ecg_data_new,scp_data[(scp_data[\"diagnostic\"] == 1)& (scp_data[\"form\"] != 1)],\"diagnostic\",\"diagnostic_namber\")\nlen(ecg_data_new_12[ecg_data_new_12.diagnostic != \"\"])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:17:12.527915Z","iopub.execute_input":"2024-06-22T17:17:12.528192Z","iopub.status.idle":"2024-06-22T17:17:15.315395Z","shell.execute_reply.started":"2024-06-22T17:17:12.528168Z","shell.execute_reply":"2024-06-22T17:17:15.314349Z"},"trusted":true},"execution_count":32,"outputs":[{"execution_count":32,"output_type":"execute_result","data":{"text/plain":"19573"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_new_12[ecg_data_new_12.diagnostic == \"IMI\"].rhythm.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:17:15.316600Z","iopub.execute_input":"2024-06-22T17:17:15.316920Z","iopub.status.idle":"2024-06-22T17:17:15.332354Z","shell.execute_reply.started":"2024-06-22T17:17:15.316892Z","shell.execute_reply":"2024-06-22T17:17:15.331365Z"},"trusted":true},"execution_count":33,"outputs":[{"execution_count":33,"output_type":"execute_result","data":{"text/plain":"rhythm\nSR       898\nAFIB      80\nSARRH     51\nSTACH     46\n          45\nSBRAD     24\nAFLT       2\nSVTAC      2\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_new_12","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:17:15.333458Z","iopub.execute_input":"2024-06-22T17:17:15.333726Z","iopub.status.idle":"2024-06-22T17:17:15.361553Z","shell.execute_reply.started":"2024-06-22T17:17:15.333701Z","shell.execute_reply":"2024-06-22T17:17:15.360591Z"},"trusted":true},"execution_count":34,"outputs":[{"execution_count":34,"output_type":"execute_result","data":{"text/plain":"        patient_id    age  sex  weight  \\\necg_id                                   \n1          15709.0   56.0    1    63.0   \n2          13243.0   19.0    0    70.0   \n3          20372.0   37.0    1    69.0   \n4          17014.0   24.0    0    82.0   \n5          17448.0   19.0    1    70.0   \n...            ...    ...  ...     ...   \n21833      17180.0   67.0    1     NaN   \n21834      20703.0  300.0    0     NaN   \n21835      19311.0   59.0    1     NaN   \n21836       8873.0   64.0    1     NaN   \n21837      11744.0   68.0    0     NaN   \n\n                                                   report  \\\necg_id                                                      \n1                  sinusrhythmus periphere niederspannung   \n2                     sinusbradykardie sonst normales ekg   \n3                              sinusrhythmus normales ekg   \n4                              sinusrhythmus normales ekg   \n5                              sinusrhythmus normales ekg   \n...                                                   ...   \n21833   ventrikulÄre extrasystole(n) sinustachykardie ...   \n21834   sinusrhythmus lagetyp normal qrs(t) abnorm    ...   \n21835   sinusrhythmus lagetyp normal t abnorm in anter...   \n21836   supraventrikulÄre extrasystole(n) sinusrhythmu...   \n21837   sinusrhythmus p-sinistrocardiale lagetyp norma...   \n\n                                              scp_codes electrodes_problems  \\\necg_id                                                                        \n1                     NORM: 100.0, LVOLT: 0.0, SR: 0.0,                 NaN   \n2                               NORM: 80.0, SBRAD: 0.0,                 NaN   \n3                                 NORM: 100.0, SR: 0.0,                 NaN   \n4                                 NORM: 100.0, SR: 0.0,                 NaN   \n5                                 NORM: 100.0, SR: 0.0,                 NaN   \n...                                                 ...                 ...   \n21833   NDT: 100.0, PVC: 100.0, VCLVH: 0.0, STACH: 0.0,                 NaN   \n21834                 NORM: 100.0, ABQRS: 0.0, SR: 0.0,                 NaN   \n21835                             ISCAS: 50.0, SR: 0.0,                 NaN   \n21836                             NORM: 100.0, SR: 0.0,                 NaN   \n21837                             NORM: 100.0, SR: 0.0,                 NaN   \n\n                      filename_lr                filename_hr rhythm  \\\necg_id                                                                \n1       records100/00000/00001_lr  records500/00000/00001_hr     SR   \n2       records100/00000/00002_lr  records500/00000/00002_hr  SBRAD   \n3       records100/00000/00003_lr  records500/00000/00003_hr     SR   \n4       records100/00000/00004_lr  records500/00000/00004_hr     SR   \n5       records100/00000/00005_lr  records500/00000/00005_hr     SR   \n...                           ...                        ...    ...   \n21833   records100/21000/21833_lr  records500/21000/21833_hr  STACH   \n21834   records100/21000/21834_lr  records500/21000/21834_hr     SR   \n21835   records100/21000/21835_lr  records500/21000/21835_hr     SR   \n21836   records100/21000/21836_lr  records500/21000/21836_hr     SR   \n21837   records100/21000/21837_lr  records500/21000/21837_hr     SR   \n\n       rhythm_number diagnostic diagnostic_namber  \necg_id                                             \n1                0.0       NORM             100.0  \n2                0.0       NORM              80.0  \n3                0.0       NORM             100.0  \n4                0.0       NORM             100.0  \n5                0.0       NORM             100.0  \n...              ...        ...               ...  \n21833            0.0                               \n21834            0.0       NORM             100.0  \n21835            0.0      ISCAS              50.0  \n21836            0.0       NORM             100.0  \n21837            0.0       NORM             100.0  \n\n[21758 rows x 13 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>weight</th>\n      <th>report</th>\n      <th>scp_codes</th>\n      <th>electrodes_problems</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n      <th>rhythm</th>\n      <th>rhythm_number</th>\n      <th>diagnostic</th>\n      <th>diagnostic_namber</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>15709.0</td>\n      <td>56.0</td>\n      <td>1</td>\n      <td>63.0</td>\n      <td>sinusrhythmus periphere niederspannung</td>\n      <td>NORM: 100.0, LVOLT: 0.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00001_lr</td>\n      <td>records500/00000/00001_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>13243.0</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>70.0</td>\n      <td>sinusbradykardie sonst normales ekg</td>\n      <td>NORM: 80.0, SBRAD: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00002_lr</td>\n      <td>records500/00000/00002_hr</td>\n      <td>SBRAD</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>80.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>20372.0</td>\n      <td>37.0</td>\n      <td>1</td>\n      <td>69.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00003_lr</td>\n      <td>records500/00000/00003_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>17014.0</td>\n      <td>24.0</td>\n      <td>0</td>\n      <td>82.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00004_lr</td>\n      <td>records500/00000/00004_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>17448.0</td>\n      <td>19.0</td>\n      <td>1</td>\n      <td>70.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00005_lr</td>\n      <td>records500/00000/00005_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>21833</th>\n      <td>17180.0</td>\n      <td>67.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>ventrikulÄre extrasystole(n) sinustachykardie ...</td>\n      <td>NDT: 100.0, PVC: 100.0, VCLVH: 0.0, STACH: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/21000/21833_lr</td>\n      <td>records500/21000/21833_hr</td>\n      <td>STACH</td>\n      <td>0.0</td>\n      <td></td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>21834</th>\n      <td>20703.0</td>\n      <td>300.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>sinusrhythmus lagetyp normal qrs(t) abnorm    ...</td>\n      <td>NORM: 100.0, ABQRS: 0.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/21000/21834_lr</td>\n      <td>records500/21000/21834_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>21835</th>\n      <td>19311.0</td>\n      <td>59.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>sinusrhythmus lagetyp normal t abnorm in anter...</td>\n      <td>ISCAS: 50.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/21000/21835_lr</td>\n      <td>records500/21000/21835_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>ISCAS</td>\n      <td>50.0</td>\n    </tr>\n    <tr>\n      <th>21836</th>\n      <td>8873.0</td>\n      <td>64.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>supraventrikulÄre extrasystole(n) sinusrhythmu...</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/21000/21836_lr</td>\n      <td>records500/21000/21836_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>21837</th>\n      <td>11744.0</td>\n      <td>68.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>sinusrhythmus p-sinistrocardiale lagetyp norma...</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/21000/21837_lr</td>\n      <td>records500/21000/21837_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n  </tbody>\n</table>\n<p>21758 rows × 13 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"markdown","source":"# **Второй датасет a-large-scale-12-lead-electrocardiogram-database-for-arrhythmia-study**","metadata":{}},{"cell_type":"code","source":"import os\n# Указываем путь к директории\ndirectory = \"/kaggle/input/chapman-ecg-database/a-large-scale-12-lead-electrocardiogram-database-for-arrhythmia-study-1.0.0/WFDBRecords/\"\nlist_path_file = os.listdir(directory)\npath_file_new=[]\nfor i in list_path_file:\n    directory_2 = directory + i + \"/\"\n    for j in os.listdir(directory_2):\n        path_file_new.append( i + \"/\" + j )\npath_file_new_2 = []    \necg_id=[]\nfilename=[]\nfor i in path_file_new:\n    directory_2 = directory + i + \"/\"\n    for j in os.listdir(directory_2):\n        j = j.replace(\".hea\", \"\")\n        j = j.replace(\".mat\", \"\")\n        if j!=\"RECORDS\":\n            if j in filename:\n                f=0\n            else:\n                filename.append(str(j))\n                path_file_new_2.append(i+ \"/\")\n            #+ j\n                ecg_id.append(int(j[2:]))\n            \npath_file_new_2.sort()   \necg_id.sort()\nfilename.sort()\npath_file_new_2 = pd.DataFrame({\"ecg_id\":ecg_id,\"filename_path\":path_file_new_2,\"filename\":filename,})","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:18:02.718621Z","iopub.execute_input":"2024-06-22T17:18:02.719319Z","iopub.status.idle":"2024-06-22T17:19:15.181395Z","shell.execute_reply.started":"2024-06-22T17:18:02.719284Z","shell.execute_reply":"2024-06-22T17:19:15.180590Z"},"trusted":true},"execution_count":37,"outputs":[]},{"cell_type":"code","source":"path_file_new_2[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:19:15.183230Z","iopub.execute_input":"2024-06-22T17:19:15.183800Z","iopub.status.idle":"2024-06-22T17:19:15.193038Z","shell.execute_reply.started":"2024-06-22T17:19:15.183765Z","shell.execute_reply":"2024-06-22T17:19:15.192017Z"},"trusted":true},"execution_count":38,"outputs":[{"execution_count":38,"output_type":"execute_result","data":{"text/plain":"   ecg_id filename_path filename\n0       1       01/010/  JS00001\n1       2       01/010/  JS00002","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ecg_id</th>\n      <th>filename_path</th>\n      <th>filename</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>01/010/</td>\n      <td>JS00001</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>01/010/</td>\n      <td>JS00002</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"def load_diagnos_Dx(df, path,scp_data):\n    Age = []\n    Sex = []\n    Dx = []\n    for i in df.index:\n        data = [wfdb.rdsamp(os.path.join(path+\"WFDBRecords/\" + df.filename_path[int(i)], df.filename[int(i)]))]\n        #data = np.array([signal for signal, meta in data])\n        data_hea_comments = list(pd.DataFrame(data)[1])[0]['comments']\n        Age.append(data_hea_comments[0][len(\"Age: \"):len(data_hea_comments[0])])\n        Sex.append(data_hea_comments[1][len(\"Sex: \"):len(data_hea_comments[1])])\n        Dx.append(data_hea_comments[2][len(\"Dx: \"):len(data_hea_comments[2])])\n    df[\"Age\"] = Age\n    df[\"Sex\"] = Sex\n    df[\"Dx\"] = Dx\n    return df","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:28:41.598707Z","iopub.execute_input":"2024-06-22T17:28:41.599094Z","iopub.status.idle":"2024-06-22T17:28:41.606482Z","shell.execute_reply.started":"2024-06-22T17:28:41.599058Z","shell.execute_reply":"2024-06-22T17:28:41.605625Z"},"trusted":true},"execution_count":68,"outputs":[]},{"cell_type":"code","source":"ecg_data_2 = path_file_new_2.copy()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:19:15.206712Z","iopub.execute_input":"2024-06-22T17:19:15.207094Z","iopub.status.idle":"2024-06-22T17:19:15.213240Z","shell.execute_reply.started":"2024-06-22T17:19:15.207058Z","shell.execute_reply":"2024-06-22T17:19:15.212442Z"},"trusted":true},"execution_count":40,"outputs":[]},{"cell_type":"code","source":"path_2 = '/kaggle/input/chapman-ecg-database/a-large-scale-12-lead-electrocardiogram-database-for-arrhythmia-study-1.0.0/'\nscp_data_2 = pd.read_csv(path_2 + 'ConditionNames_SNOMED-CT.csv')","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:19:15.214300Z","iopub.execute_input":"2024-06-22T17:19:15.214605Z","iopub.status.idle":"2024-06-22T17:19:15.226220Z","shell.execute_reply.started":"2024-06-22T17:19:15.214579Z","shell.execute_reply":"2024-06-22T17:19:15.225284Z"},"trusted":true},"execution_count":41,"outputs":[]},{"cell_type":"code","source":"scp_data_2_AcronymName = scp_data_2[\"Acronym Name\"].copy()\n#for i in scp_data_2.index:\n#    if len(scp_data[scp_data[\"Unnamed: 0\"]== scp_data_2[\"Acronym Name\"][i]]) == 1:\n#        scp_data_2_AcronymName[i] =\"Да\"\nscp_data_2[\"scp_data\"] = scp_data_2_AcronymName\n#lengh = scp_data_2[scp_data_2[\"scp_data\"] != \"Да\"].index\nlengh=[ 2,  3,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\n       21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40,\n       41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 55, 56, 57, 58, 59, 60, 61,\n       62]\nscp_data_2.scp_data.loc[lengh[0]] = scp_data_2[\"Acronym Name\"].loc[lengh[0]][:-1]\nscp_data_2.scp_data.loc[lengh[1]] = scp_data_2[\"Acronym Name\"].loc[lengh[1]][:-1]\nscp_data_2.scp_data.loc[lengh[4]] = \"PAC\"\nscp_data_2.scp_data.loc[lengh[16]] = \"CLBBB\"\nscp_data_2.scp_data.loc[lengh[17]] = \"CLBBB\"\nscp_data_2.scp_data.loc[lengh[18]] = \"CLBBB\"\nscp_data_2.scp_data.loc[lengh[23]] = \"PMI\"\nscp_data_2.scp_data.loc[lengh[24]] = \"AMI\"\nscp_data_2.scp_data.loc[lengh[25]] = \"IMI\"\nscp_data_2.scp_data.loc[lengh[26]] = \"LMI\"\nscp_data_2.scp_data.loc[lengh[42]] = \"PVC\"\nscp_data_2.scp_data.loc[lengh[46]] = \"SBRAD\"\nscp_data_2.scp_data.loc[lengh[47]] = \"STACH\"\nscp_data_2.scp_data.loc[lengh[48]] = \"AFLT\"\nscp_data_2.scp_data.loc[lengh[50]] = \"SVTAC\"\nscp_data_2[\"Acronym Name\"] = scp_data_2[\"scp_data\"]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:19:15.227407Z","iopub.execute_input":"2024-06-22T17:19:15.227691Z","iopub.status.idle":"2024-06-22T17:19:15.246286Z","shell.execute_reply.started":"2024-06-22T17:19:15.227665Z","shell.execute_reply":"2024-06-22T17:19:15.245379Z"},"trusted":true},"execution_count":42,"outputs":[]},{"cell_type":"code","source":"scp_data_2[:2000]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:24:39.290951Z","iopub.execute_input":"2024-06-22T17:24:39.291870Z","iopub.status.idle":"2024-06-22T17:24:39.308578Z","shell.execute_reply.started":"2024-06-22T17:24:39.291816Z","shell.execute_reply":"2024-06-22T17:24:39.307707Z"},"trusted":true},"execution_count":58,"outputs":[{"execution_count":58,"output_type":"execute_result","data":{"text/plain":"   Acronym Name                                     Full Name  Snomed_CT  \\\n0          1AVB               1 degree atrioventricular block  270492004   \n1          2AVB               2 degree atrioventricular block  195042002   \n2          2AVB     2 degree atrioventricular block(Type one)   54016002   \n3          2AVB     2 degree atrioventricular block(Type two)   28189009   \n4          3AVB               3 degree atrioventricular block   27885002   \n..          ...                                           ...        ...   \n58        SVTAC                  Supraventricular Tachycardia  426761007   \n59           AT                            Atrial Tachycardia  713422000   \n60        AVNRT  Atrioventricular  Node Reentrant Tachycardia  233896004   \n61         AVRT        Atrioventricular Reentrant Tachycardia  233897008   \n62        SAAWR       Sinus Atrium to Atrial Wandering Rhythm  195101003   \n\n   scp_data  \n0      1AVB  \n1      2AVB  \n2      2AVB  \n3      2AVB  \n4      3AVB  \n..      ...  \n58    SVTAC  \n59       AT  \n60    AVNRT  \n61     AVRT  \n62    SAAWR  \n\n[63 rows x 4 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Acronym Name</th>\n      <th>Full Name</th>\n      <th>Snomed_CT</th>\n      <th>scp_data</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1AVB</td>\n      <td>1 degree atrioventricular block</td>\n      <td>270492004</td>\n      <td>1AVB</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2AVB</td>\n      <td>2 degree atrioventricular block</td>\n      <td>195042002</td>\n      <td>2AVB</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2AVB</td>\n      <td>2 degree atrioventricular block(Type one)</td>\n      <td>54016002</td>\n      <td>2AVB</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2AVB</td>\n      <td>2 degree atrioventricular block(Type two)</td>\n      <td>28189009</td>\n      <td>2AVB</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>3AVB</td>\n      <td>3 degree atrioventricular block</td>\n      <td>27885002</td>\n      <td>3AVB</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>58</th>\n      <td>SVTAC</td>\n      <td>Supraventricular Tachycardia</td>\n      <td>426761007</td>\n      <td>SVTAC</td>\n    </tr>\n    <tr>\n      <th>59</th>\n      <td>AT</td>\n      <td>Atrial Tachycardia</td>\n      <td>713422000</td>\n      <td>AT</td>\n    </tr>\n    <tr>\n      <th>60</th>\n      <td>AVNRT</td>\n      <td>Atrioventricular  Node Reentrant Tachycardia</td>\n      <td>233896004</td>\n      <td>AVNRT</td>\n    </tr>\n    <tr>\n      <th>61</th>\n      <td>AVRT</td>\n      <td>Atrioventricular Reentrant Tachycardia</td>\n      <td>233897008</td>\n      <td>AVRT</td>\n    </tr>\n    <tr>\n      <th>62</th>\n      <td>SAAWR</td>\n      <td>Sinus Atrium to Atrial Wandering Rhythm</td>\n      <td>195101003</td>\n      <td>SAAWR</td>\n    </tr>\n  </tbody>\n</table>\n<p>63 rows × 4 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"#ecg_data_2 = ecg_data_2.drop(labels = [999],axis = 0)\n#ecg_data_2 = ecg_data_2.drop(labels = [22674],axis = 0)\n#ecg_data_2 = ecg_data_2.drop(labels = [999],axis = 0)","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:17:15.446714Z","iopub.status.idle":"2024-06-22T17:17:15.447068Z","shell.execute_reply.started":"2024-06-22T17:17:15.446885Z","shell.execute_reply":"2024-06-22T17:17:15.446900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Заргузка кодов из .hea ","metadata":{}},{"cell_type":"code","source":"ecg_data_2[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:24:25.064941Z","iopub.execute_input":"2024-06-22T17:24:25.065727Z","iopub.status.idle":"2024-06-22T17:24:25.074432Z","shell.execute_reply.started":"2024-06-22T17:24:25.065694Z","shell.execute_reply":"2024-06-22T17:24:25.073421Z"},"trusted":true},"execution_count":56,"outputs":[{"execution_count":56,"output_type":"execute_result","data":{"text/plain":"   ecg_id filename_path filename\n0       1       01/010/  JS00001\n1       2       01/010/  JS00002","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ecg_id</th>\n      <th>filename_path</th>\n      <th>filename</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>01/010/</td>\n      <td>JS00001</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>01/010/</td>\n      <td>JS00002</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_2[998:1002]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:25:08.810432Z","iopub.execute_input":"2024-06-22T17:25:08.811317Z","iopub.status.idle":"2024-06-22T17:25:08.820525Z","shell.execute_reply.started":"2024-06-22T17:25:08.811283Z","shell.execute_reply":"2024-06-22T17:25:08.819453Z"},"trusted":true},"execution_count":59,"outputs":[{"execution_count":59,"output_type":"execute_result","data":{"text/plain":"      ecg_id filename_path filename\n998     1051       01/019/  JS01051\n999     1052       01/019/  JS01052\n1000    1053       02/020/  JS01053\n1001    1054       02/020/  JS01054","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ecg_id</th>\n      <th>filename_path</th>\n      <th>filename</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>998</th>\n      <td>1051</td>\n      <td>01/019/</td>\n      <td>JS01051</td>\n    </tr>\n    <tr>\n      <th>999</th>\n      <td>1052</td>\n      <td>01/019/</td>\n      <td>JS01052</td>\n    </tr>\n    <tr>\n      <th>1000</th>\n      <td>1053</td>\n      <td>02/020/</td>\n      <td>JS01053</td>\n    </tr>\n    <tr>\n      <th>1001</th>\n      <td>1054</td>\n      <td>02/020/</td>\n      <td>JS01054</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_2_df = load_diagnos_Dx(ecg_data_2, path_2,scp_data_2)","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:42:25.417644Z","iopub.execute_input":"2024-06-22T17:42:25.418487Z","iopub.status.idle":"2024-06-22T17:42:25.422356Z","shell.execute_reply.started":"2024-06-22T17:42:25.418450Z","shell.execute_reply":"2024-06-22T17:42:25.421510Z"},"trusted":true},"execution_count":85,"outputs":[]},{"cell_type":"code","source":"ecg_data_2_df[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:47:27.382447Z","iopub.execute_input":"2024-06-22T17:47:27.383099Z","iopub.status.idle":"2024-06-22T17:47:27.393888Z","shell.execute_reply.started":"2024-06-22T17:47:27.383063Z","shell.execute_reply":"2024-06-22T17:47:27.392988Z"},"trusted":true},"execution_count":87,"outputs":[{"execution_count":87,"output_type":"execute_result","data":{"text/plain":"   ecg_id filename_path filename   Age     Sex                            Dx\n0       1       01/010/  JS00001  85.0    Male  164889003,59118001,164934002\n1       2       01/010/  JS00002  59.0  Female           426177001,164934002","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ecg_id</th>\n      <th>filename_path</th>\n      <th>filename</th>\n      <th>Age</th>\n      <th>Sex</th>\n      <th>Dx</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>01/010/</td>\n      <td>JS00001</td>\n      <td>85.0</td>\n      <td>Male</td>\n      <td>164889003,59118001,164934002</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>01/010/</td>\n      <td>JS00002</td>\n      <td>59.0</td>\n      <td>Female</td>\n      <td>426177001,164934002</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"# Сохранили и загрузили файл для последующей работы из буфера\necg_data_2_df = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/ecg_data_2.csv\",index_col=\"Unnamed: 0\")","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:47:38.633099Z","iopub.execute_input":"2024-06-22T17:47:38.633707Z","iopub.status.idle":"2024-06-22T17:47:38.709218Z","shell.execute_reply.started":"2024-06-22T17:47:38.633673Z","shell.execute_reply":"2024-06-22T17:47:38.708285Z"},"trusted":true},"execution_count":88,"outputs":[]},{"cell_type":"markdown","source":"Расшифровка","metadata":{}},{"cell_type":"code","source":"Dx_str= ecg_data_2_df.Dx\nDx_str_new=[]\nfor i in Dx_str:\n    Dx_str_CT= \"\"\n    i=i.split(\",\")\n    for j in i:\n        if len(str(list(scp_data_2[scp_data_2.Snomed_CT== int(j)][\"scp_data\"]))[1:-1])>1:\n            Dx_str_CT += str(list(scp_data_2[scp_data_2.Snomed_CT== int(j)][\"scp_data\"]))[2:-2] +\",\"\n    Dx_str_new.append(Dx_str_CT[:-1])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:47:40.509073Z","iopub.execute_input":"2024-06-22T17:47:40.509515Z","iopub.status.idle":"2024-06-22T17:48:38.350413Z","shell.execute_reply.started":"2024-06-22T17:47:40.509481Z","shell.execute_reply":"2024-06-22T17:48:38.349580Z"},"trusted":true},"execution_count":89,"outputs":[]},{"cell_type":"code","source":"ecg_data_2_df[\"diagnos\"] = Dx_str_new","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:48:38.352181Z","iopub.execute_input":"2024-06-22T17:48:38.352468Z","iopub.status.idle":"2024-06-22T17:48:38.360860Z","shell.execute_reply.started":"2024-06-22T17:48:38.352441Z","shell.execute_reply":"2024-06-22T17:48:38.360025Z"},"trusted":true},"execution_count":90,"outputs":[]},{"cell_type":"code","source":"ecg_data_2_df[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:48:38.361908Z","iopub.execute_input":"2024-06-22T17:48:38.362567Z","iopub.status.idle":"2024-06-22T17:48:38.377853Z","shell.execute_reply.started":"2024-06-22T17:48:38.362541Z","shell.execute_reply":"2024-06-22T17:48:38.376959Z"},"trusted":true},"execution_count":91,"outputs":[{"execution_count":91,"output_type":"execute_result","data":{"text/plain":"   ecg_id filename_path filename   Age     Sex                            Dx  \\\n0       1       01/010/  JS00001  85.0    Male  164889003,59118001,164934002   \n1       2       01/010/  JS00002  59.0  Female           426177001,164934002   \n\n         diagnos  \n0  AFIB,RBBB,TWC  \n1      SBRAD,TWC  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ecg_id</th>\n      <th>filename_path</th>\n      <th>filename</th>\n      <th>Age</th>\n      <th>Sex</th>\n      <th>Dx</th>\n      <th>diagnos</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>01/010/</td>\n      <td>JS00001</td>\n      <td>85.0</td>\n      <td>Male</td>\n      <td>164889003,59118001,164934002</td>\n      <td>AFIB,RBBB,TWC</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>01/010/</td>\n      <td>JS00002</td>\n      <td>59.0</td>\n      <td>Female</td>\n      <td>426177001,164934002</td>\n      <td>SBRAD,TWC</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_new_12[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:48:38.379933Z","iopub.execute_input":"2024-06-22T17:48:38.380524Z","iopub.status.idle":"2024-06-22T17:48:38.396817Z","shell.execute_reply.started":"2024-06-22T17:48:38.380490Z","shell.execute_reply":"2024-06-22T17:48:38.395897Z"},"trusted":true},"execution_count":92,"outputs":[{"execution_count":92,"output_type":"execute_result","data":{"text/plain":"        patient_id   age  sex  weight                                  report  \\\necg_id                                                                          \n1          15709.0  56.0    1    63.0  sinusrhythmus periphere niederspannung   \n2          13243.0  19.0    0    70.0     sinusbradykardie sonst normales ekg   \n\n                                scp_codes electrodes_problems  \\\necg_id                                                          \n1       NORM: 100.0, LVOLT: 0.0, SR: 0.0,                 NaN   \n2                 NORM: 80.0, SBRAD: 0.0,                 NaN   \n\n                      filename_lr                filename_hr rhythm  \\\necg_id                                                                \n1       records100/00000/00001_lr  records500/00000/00001_hr     SR   \n2       records100/00000/00002_lr  records500/00000/00002_hr  SBRAD   \n\n       rhythm_number diagnostic diagnostic_namber  \necg_id                                             \n1                0.0       NORM             100.0  \n2                0.0       NORM              80.0  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>weight</th>\n      <th>report</th>\n      <th>scp_codes</th>\n      <th>electrodes_problems</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n      <th>rhythm</th>\n      <th>rhythm_number</th>\n      <th>diagnostic</th>\n      <th>diagnostic_namber</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>15709.0</td>\n      <td>56.0</td>\n      <td>1</td>\n      <td>63.0</td>\n      <td>sinusrhythmus periphere niederspannung</td>\n      <td>NORM: 100.0, LVOLT: 0.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00001_lr</td>\n      <td>records500/00000/00001_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>13243.0</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>70.0</td>\n      <td>sinusbradykardie sonst normales ekg</td>\n      <td>NORM: 80.0, SBRAD: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00002_lr</td>\n      <td>records500/00000/00002_hr</td>\n      <td>SBRAD</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>80.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"markdown","source":"Разделение на диагнозы и нарушения ритма","metadata":{}},{"cell_type":"code","source":"def f_rhythm_diagnostic(ecg_data_2_df , name):\n    df_l=[]\n    for i in ecg_data_2_df.index:\n        l_ = \"\"\n        for j in ecg_data_2_df.diagnos[i].split(\",\"):\n            if str(j) in list(ecg_data_new_12[name].value_counts().index) or str(j) in list(ecg_data_new_12[name].value_counts().index) :\n                l_ = l_ + j +\",\"\n        df_l.append(l_[:-1])\n    return df_l\necg_data_2_df[\"rhythm\"] = f_rhythm_diagnostic(ecg_data_2_df , \"rhythm\")\necg_data_2_df[\"diagnostic\"] = f_rhythm_diagnostic(ecg_data_2_df , \"diagnostic\")","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:49:37.162710Z","iopub.execute_input":"2024-06-22T17:49:37.163562Z","iopub.status.idle":"2024-06-22T18:04:21.761047Z","shell.execute_reply.started":"2024-06-22T17:49:37.163525Z","shell.execute_reply":"2024-06-22T18:04:21.759982Z"},"trusted":true},"execution_count":93,"outputs":[]},{"cell_type":"code","source":"ecg_data_2_df[:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:04:21.763199Z","iopub.execute_input":"2024-06-22T18:04:21.763615Z","iopub.status.idle":"2024-06-22T18:04:21.777833Z","shell.execute_reply.started":"2024-06-22T18:04:21.763578Z","shell.execute_reply":"2024-06-22T18:04:21.776959Z"},"trusted":true},"execution_count":94,"outputs":[{"execution_count":94,"output_type":"execute_result","data":{"text/plain":"   ecg_id filename_path filename   Age     Sex                            Dx  \\\n0       1       01/010/  JS00001  85.0    Male  164889003,59118001,164934002   \n1       2       01/010/  JS00002  59.0  Female           426177001,164934002   \n\n         diagnos rhythm diagnostic  \n0  AFIB,RBBB,TWC   AFIB             \n1      SBRAD,TWC  SBRAD             ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ecg_id</th>\n      <th>filename_path</th>\n      <th>filename</th>\n      <th>Age</th>\n      <th>Sex</th>\n      <th>Dx</th>\n      <th>diagnos</th>\n      <th>rhythm</th>\n      <th>diagnostic</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>01/010/</td>\n      <td>JS00001</td>\n      <td>85.0</td>\n      <td>Male</td>\n      <td>164889003,59118001,164934002</td>\n      <td>AFIB,RBBB,TWC</td>\n      <td>AFIB</td>\n      <td></td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>01/010/</td>\n      <td>JS00002</td>\n      <td>59.0</td>\n      <td>Female</td>\n      <td>426177001,164934002</td>\n      <td>SBRAD,TWC</td>\n      <td>SBRAD</td>\n      <td></td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_2_df.rhythm.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:04:21.778953Z","iopub.execute_input":"2024-06-22T18:04:21.779298Z","iopub.status.idle":"2024-06-22T18:04:21.794699Z","shell.execute_reply.started":"2024-06-22T18:04:21.779262Z","shell.execute_reply":"2024-06-22T18:04:21.793857Z"},"trusted":true},"execution_count":95,"outputs":[{"execution_count":95,"output_type":"execute_result","data":{"text/plain":"rhythm\nSBRAD          16552\nSR              8099\nAFLT            7984\nSTACH           7239\n                2736\nAFIB            1780\nSVTAC            672\nSVTAC,AFLT        43\nSR,AFLT           15\nSBRAD,SR           6\nAFLT,SR            5\nSTACH,AFLT         5\nAFLT,STACH         4\nSTACH,SVTAC        3\nSVTAC,STACH        3\nAFLT,SVTAC         3\nSBRAD,AFLT         1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_2_df.diagnostic.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:04:21.796666Z","iopub.execute_input":"2024-06-22T18:04:21.796948Z","iopub.status.idle":"2024-06-22T18:04:21.810598Z","shell.execute_reply.started":"2024-06-22T18:04:21.796923Z","shell.execute_reply":"2024-06-22T18:04:21.809685Z"},"trusted":true},"execution_count":96,"outputs":[{"execution_count":96,"output_type":"execute_result","data":{"text/plain":"diagnostic\n                43050\n1AVB             1116\nLVH               617\nRVH                99\n2AVB               86\nWPW                72\n3AVB               69\n1AVB,LVH           15\n1AVB,2AVB           6\nLVH,2AVB            5\nRVH,LVH             5\n3AVB,LVH            4\nRVH,3AVB            3\nRVH,1AVB            2\nRVH,1AVB,LVH        1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"#ecg_data_2_df.to_csv(\"ecg_data_2_df.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-06-22T17:17:15.469191Z","iopub.status.idle":"2024-06-22T17:17:15.469538Z","shell.execute_reply.started":"2024-06-22T17:17:15.469375Z","shell.execute_reply":"2024-06-22T17:17:15.469391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Обьеденение 2-х датасетов для выявления общего количиства лиагнозов и ритма","metadata":{}},{"cell_type":"code","source":"pd.concat([ecg_data_new_12.rhythm,\necg_data_2_df.rhythm]).value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:09:40.624456Z","iopub.execute_input":"2024-06-22T18:09:40.624850Z","iopub.status.idle":"2024-06-22T18:09:40.644223Z","shell.execute_reply.started":"2024-06-22T18:09:40.624817Z","shell.execute_reply":"2024-06-22T18:09:40.643245Z"},"trusted":true},"execution_count":104,"outputs":[{"execution_count":104,"output_type":"execute_result","data":{"text/plain":"rhythm\nSR             24838\nSBRAD          17186\nSTACH           8060\nAFLT            8024\n                3979\nAFIB            3276\nSARRH            767\nSVTAC            690\nSVTAC,AFLT        43\nSR,AFLT           15\nSBRAD,SR           6\nAFLT,SR            5\nSTACH,AFLT         5\nAFLT,STACH         4\nSTACH,SVTAC        3\nSVTAC,STACH        3\nAFLT,SVTAC         3\nSBRAD,AFLT         1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"pd.concat([ecg_data_new_12.diagnostic,\necg_data_2_df.diagnostic]).value_counts()[:20]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:10:18.281635Z","iopub.execute_input":"2024-06-22T18:10:18.282013Z","iopub.status.idle":"2024-06-22T18:10:18.301550Z","shell.execute_reply.started":"2024-06-22T18:10:18.281965Z","shell.execute_reply":"2024-06-22T18:10:18.300584Z"},"trusted":true},"execution_count":106,"outputs":[{"execution_count":106,"output_type":"execute_result","data":{"text/plain":"diagnostic\n                45235\nNORM             9094\n1AVB             1223\nLVH              1192\nIMI              1148\nLAFB              525\nLVH,ISC_          459\nASMI              441\nIRBBB             361\nCLBBB             359\nNORM,IRBBB        243\nILMI,LMI          182\nASMI,LAFB         170\nIVCD              153\nIMI,ASMI          150\nWPW               142\nASMI,IMI          139\nISCAL             136\nIMI,LVH,ISC_      111\nCRBBB             109\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_2_df.to_csv(\"df_arrhytmia.csv\")\necg_data_new_12.to_csv(\"df_ptb_xl.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:04:28.448319Z","iopub.execute_input":"2024-06-22T18:04:28.448739Z","iopub.status.idle":"2024-06-22T18:04:29.064118Z","shell.execute_reply.started":"2024-06-22T18:04:28.448691Z","shell.execute_reply":"2024-06-22T18:04:29.063334Z"},"trusted":true},"execution_count":102,"outputs":[]},{"cell_type":"markdown","source":"Удаление шумовых данных","metadata":{}},{"cell_type":"code","source":"ecg_data_new_12[5:10] # ecg_data","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:10:28.325504Z","iopub.execute_input":"2024-06-22T18:10:28.325895Z","iopub.status.idle":"2024-06-22T18:10:28.344184Z","shell.execute_reply.started":"2024-06-22T18:10:28.325860Z","shell.execute_reply":"2024-06-22T18:10:28.343191Z"},"trusted":true},"execution_count":107,"outputs":[{"execution_count":107,"output_type":"execute_result","data":{"text/plain":"        patient_id   age  sex  weight  \\\necg_id                                  \n6          19005.0  18.0    1    58.0   \n7          16193.0  54.0    0    83.0   \n8          11275.0  48.0    0    95.0   \n9          18792.0  55.0    0    70.0   \n10          9456.0  22.0    1    56.0   \n\n                                                   report  \\\necg_id                                                      \n6                              sinusrhythmus normales ekg   \n7       sinusrhythmus linkstyp t abnormal, wahrscheinl...   \n8       sinusrhythmus linkstyp qrs(t) abnormal    infe...   \n9                              sinusrhythmus normales ekg   \n10                             sinusrhythmus normales ekg   \n\n                              scp_codes electrodes_problems  \\\necg_id                                                        \n6                 NORM: 100.0, SR: 0.0,                 NaN   \n7                 NORM: 100.0, SR: 0.0,                 NaN   \n8       IMI: 35.0, ABQRS: 0.0, SR: 0.0,                 NaN   \n9                 NORM: 100.0, SR: 0.0,                 NaN   \n10                NORM: 100.0, SR: 0.0,                 NaN   \n\n                      filename_lr                filename_hr rhythm  \\\necg_id                                                                \n6       records100/00000/00006_lr  records500/00000/00006_hr     SR   \n7       records100/00000/00007_lr  records500/00000/00007_hr     SR   \n8       records100/00000/00008_lr  records500/00000/00008_hr     SR   \n9       records100/00000/00009_lr  records500/00000/00009_hr     SR   \n10      records100/00000/00010_lr  records500/00000/00010_hr     SR   \n\n       rhythm_number diagnostic diagnostic_namber  \necg_id                                             \n6                0.0       NORM             100.0  \n7                0.0       NORM             100.0  \n8                0.0        IMI              35.0  \n9                0.0       NORM             100.0  \n10               0.0       NORM             100.0  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>weight</th>\n      <th>report</th>\n      <th>scp_codes</th>\n      <th>electrodes_problems</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n      <th>rhythm</th>\n      <th>rhythm_number</th>\n      <th>diagnostic</th>\n      <th>diagnostic_namber</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>6</th>\n      <td>19005.0</td>\n      <td>18.0</td>\n      <td>1</td>\n      <td>58.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00006_lr</td>\n      <td>records500/00000/00006_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>16193.0</td>\n      <td>54.0</td>\n      <td>0</td>\n      <td>83.0</td>\n      <td>sinusrhythmus linkstyp t abnormal, wahrscheinl...</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00007_lr</td>\n      <td>records500/00000/00007_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>11275.0</td>\n      <td>48.0</td>\n      <td>0</td>\n      <td>95.0</td>\n      <td>sinusrhythmus linkstyp qrs(t) abnormal    infe...</td>\n      <td>IMI: 35.0, ABQRS: 0.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00008_lr</td>\n      <td>records500/00000/00008_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>IMI</td>\n      <td>35.0</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>18792.0</td>\n      <td>55.0</td>\n      <td>0</td>\n      <td>70.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00009_lr</td>\n      <td>records500/00000/00009_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>9456.0</td>\n      <td>22.0</td>\n      <td>1</td>\n      <td>56.0</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>NORM: 100.0, SR: 0.0,</td>\n      <td>NaN</td>\n      <td>records100/00000/00010_lr</td>\n      <td>records500/00000/00010_hr</td>\n      <td>SR</td>\n      <td>0.0</td>\n      <td>NORM</td>\n      <td>100.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"path = '/kaggle/input/ptb-xl-a-large-publicly-available2/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.3/'\necg_data = pd.read_csv(path + 'ptbxl_database.csv', index_col='ecg_id')\nscp_data = pd.read_csv(path + 'scp_statements.csv', index_col=0)","metadata":{"trusted":true},"execution_count":108,"outputs":[{"execution_count":108,"output_type":"execute_result","data":{"text/plain":"        patient_id    age  sex  height  weight  nurse  site      device  \\\necg_id                                                                    \n1          15709.0   56.0    1     NaN    63.0    2.0   0.0   CS-12   E   \n2          13243.0   19.0    0     NaN    70.0    2.0   0.0   CS-12   E   \n3          20372.0   37.0    1     NaN    69.0    2.0   0.0   CS-12   E   \n4          17014.0   24.0    0     NaN    82.0    2.0   0.0   CS-12   E   \n5          17448.0   19.0    1     NaN    70.0    2.0   0.0   CS-12   E   \n...            ...    ...  ...     ...     ...    ...   ...         ...   \n21833      17180.0   67.0    1     NaN     NaN    1.0   2.0  AT-60    3   \n21834      20703.0  300.0    0     NaN     NaN    1.0   2.0  AT-60    3   \n21835      19311.0   59.0    1     NaN     NaN    1.0   2.0  AT-60    3   \n21836       8873.0   64.0    1     NaN     NaN    1.0   2.0  AT-60    3   \n21837      11744.0   68.0    0     NaN     NaN    1.0   2.0  AT-60    3   \n\n             recording_date  \\\necg_id                        \n1       1984-11-09 09:17:34   \n2       1984-11-14 12:55:37   \n3       1984-11-15 12:49:10   \n4       1984-11-15 13:44:57   \n5       1984-11-17 10:43:15   \n...                     ...   \n21833   2001-05-31 09:14:35   \n21834   2001-06-05 11:33:39   \n21835   2001-06-08 10:30:27   \n21836   2001-06-09 18:21:49   \n21837   2001-06-11 16:43:01   \n\n                                                   report  ...  \\\necg_id                                                     ...   \n1                  sinusrhythmus periphere niederspannung  ...   \n2                     sinusbradykardie sonst normales ekg  ...   \n3                              sinusrhythmus normales ekg  ...   \n4                              sinusrhythmus normales ekg  ...   \n5                              sinusrhythmus normales ekg  ...   \n...                                                   ...  ...   \n21833   ventrikulÄre extrasystole(n) sinustachykardie ...  ...   \n21834   sinusrhythmus lagetyp normal qrs(t) abnorm    ...  ...   \n21835   sinusrhythmus lagetyp normal t abnorm in anter...  ...   \n21836   supraventrikulÄre extrasystole(n) sinusrhythmu...  ...   \n21837   sinusrhythmus p-sinistrocardiale lagetyp norma...  ...   \n\n       validated_by_human  baseline_drift static_noise burst_noise  \\\necg_id                                                               \n1                    True             NaN    , I-V1,           NaN   \n2                    True             NaN          NaN         NaN   \n3                    True             NaN          NaN         NaN   \n4                    True    , II,III,AVF          NaN         NaN   \n5                    True   , III,AVR,AVF          NaN         NaN   \n...                   ...             ...          ...         ...   \n21833                True             NaN   , alles,           NaN   \n21834                True             NaN          NaN         NaN   \n21835                True             NaN   , I-AVR,           NaN   \n21836                True             NaN          NaN         NaN   \n21837                True             NaN   , I-AVL,           NaN   \n\n        electrodes_problems  extra_beats  pacemaker  strat_fold  \\\necg_id                                                            \n1                       NaN          NaN        NaN           3   \n2                       NaN          NaN        NaN           2   \n3                       NaN          NaN        NaN           5   \n4                       NaN          NaN        NaN           3   \n5                       NaN          NaN        NaN           4   \n...                     ...          ...        ...         ...   \n21833                   NaN          1ES        NaN           7   \n21834                   NaN          NaN        NaN           4   \n21835                   NaN          NaN        NaN           2   \n21836                   NaN         SVES        NaN           8   \n21837                   NaN          NaN        NaN           9   \n\n                      filename_lr                filename_hr  \necg_id                                                        \n1       records100/00000/00001_lr  records500/00000/00001_hr  \n2       records100/00000/00002_lr  records500/00000/00002_hr  \n3       records100/00000/00003_lr  records500/00000/00003_hr  \n4       records100/00000/00004_lr  records500/00000/00004_hr  \n5       records100/00000/00005_lr  records500/00000/00005_hr  \n...                           ...                        ...  \n21833   records100/21000/21833_lr  records500/21000/21833_hr  \n21834   records100/21000/21834_lr  records500/21000/21834_hr  \n21835   records100/21000/21835_lr  records500/21000/21835_hr  \n21836   records100/21000/21836_lr  records500/21000/21836_hr  \n21837   records100/21000/21837_lr  records500/21000/21837_hr  \n\n[21799 rows x 27 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>patient_id</th>\n      <th>age</th>\n      <th>sex</th>\n      <th>height</th>\n      <th>weight</th>\n      <th>nurse</th>\n      <th>site</th>\n      <th>device</th>\n      <th>recording_date</th>\n      <th>report</th>\n      <th>...</th>\n      <th>validated_by_human</th>\n      <th>baseline_drift</th>\n      <th>static_noise</th>\n      <th>burst_noise</th>\n      <th>electrodes_problems</th>\n      <th>extra_beats</th>\n      <th>pacemaker</th>\n      <th>strat_fold</th>\n      <th>filename_lr</th>\n      <th>filename_hr</th>\n    </tr>\n    <tr>\n      <th>ecg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>15709.0</td>\n      <td>56.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>63.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-09 09:17:34</td>\n      <td>sinusrhythmus periphere niederspannung</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>, I-V1,</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>3</td>\n      <td>records100/00000/00001_lr</td>\n      <td>records500/00000/00001_hr</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>13243.0</td>\n      <td>19.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>70.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-14 12:55:37</td>\n      <td>sinusbradykardie sonst normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>2</td>\n      <td>records100/00000/00002_lr</td>\n      <td>records500/00000/00002_hr</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>20372.0</td>\n      <td>37.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>69.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-15 12:49:10</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>5</td>\n      <td>records100/00000/00003_lr</td>\n      <td>records500/00000/00003_hr</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>17014.0</td>\n      <td>24.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>82.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-15 13:44:57</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>, II,III,AVF</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>3</td>\n      <td>records100/00000/00004_lr</td>\n      <td>records500/00000/00004_hr</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>17448.0</td>\n      <td>19.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>70.0</td>\n      <td>2.0</td>\n      <td>0.0</td>\n      <td>CS-12   E</td>\n      <td>1984-11-17 10:43:15</td>\n      <td>sinusrhythmus normales ekg</td>\n      <td>...</td>\n      <td>True</td>\n      <td>, III,AVR,AVF</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>4</td>\n      <td>records100/00000/00005_lr</td>\n      <td>records500/00000/00005_hr</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>21833</th>\n      <td>17180.0</td>\n      <td>67.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>2.0</td>\n      <td>AT-60    3</td>\n      <td>2001-05-31 09:14:35</td>\n      <td>ventrikulÄre extrasystole(n) sinustachykardie ...</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>, alles,</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1ES</td>\n      <td>NaN</td>\n      <td>7</td>\n      <td>records100/21000/21833_lr</td>\n      <td>records500/21000/21833_hr</td>\n    </tr>\n    <tr>\n      <th>21834</th>\n      <td>20703.0</td>\n      <td>300.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>2.0</td>\n      <td>AT-60    3</td>\n      <td>2001-06-05 11:33:39</td>\n      <td>sinusrhythmus lagetyp normal qrs(t) abnorm    ...</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>4</td>\n      <td>records100/21000/21834_lr</td>\n      <td>records500/21000/21834_hr</td>\n    </tr>\n    <tr>\n      <th>21835</th>\n      <td>19311.0</td>\n      <td>59.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>2.0</td>\n      <td>AT-60    3</td>\n      <td>2001-06-08 10:30:27</td>\n      <td>sinusrhythmus lagetyp normal t abnorm in anter...</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>, I-AVR,</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>2</td>\n      <td>records100/21000/21835_lr</td>\n      <td>records500/21000/21835_hr</td>\n    </tr>\n    <tr>\n      <th>21836</th>\n      <td>8873.0</td>\n      <td>64.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>2.0</td>\n      <td>AT-60    3</td>\n      <td>2001-06-09 18:21:49</td>\n      <td>supraventrikulÄre extrasystole(n) sinusrhythmu...</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>SVES</td>\n      <td>NaN</td>\n      <td>8</td>\n      <td>records100/21000/21836_lr</td>\n      <td>records500/21000/21836_hr</td>\n    </tr>\n    <tr>\n      <th>21837</th>\n      <td>11744.0</td>\n      <td>68.0</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>2.0</td>\n      <td>AT-60    3</td>\n      <td>2001-06-11 16:43:01</td>\n      <td>sinusrhythmus p-sinistrocardiale lagetyp norma...</td>\n      <td>...</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>, I-AVL,</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>9</td>\n      <td>records100/21000/21837_lr</td>\n      <td>records500/21000/21837_hr</td>\n    </tr>\n  </tbody>\n</table>\n<p>21799 rows × 27 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data.electrodes_problems.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:10:55.208652Z","iopub.execute_input":"2024-06-22T18:10:55.209564Z","iopub.status.idle":"2024-06-22T18:10:55.218709Z","shell.execute_reply.started":"2024-06-22T18:10:55.209516Z","shell.execute_reply":"2024-06-22T18:10:55.217704Z"},"trusted":true},"execution_count":111,"outputs":[{"execution_count":111,"output_type":"execute_result","data":{"text/plain":"electrodes_problems\nV6                          8\nV4                          5\nV1                          4\nV1???                       2\nV5                          2\nV3                          1\nV5,V6                       1\nKontaktprobleme aVL ???     1\nI???                        1\naVL???                      1\nv6????                      1\nElektroden vertauscht???    1\nv4, v5                      1\nV3,V4-V6                    1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"for i in ecg_data_new_12.index:\n    if ecg_data_new_12.electrodes_problems[i] in ecg_data_new_12.electrodes_problems.value_counts().index:\n        ecg_data_new_12 = ecg_data_new_12.drop(labels = [i],axis = 0)\necg_data_ptb_xl =ecg_data_new_12[(ecg_data_new_12.diagnostic != \"\") & (ecg_data_new_12.rhythm != \"\")]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:13:28.226793Z","iopub.execute_input":"2024-06-22T18:13:28.227617Z","iopub.status.idle":"2024-06-22T18:13:49.660199Z","shell.execute_reply.started":"2024-06-22T18:13:28.227586Z","shell.execute_reply":"2024-06-22T18:13:49.659412Z"},"trusted":true},"execution_count":115,"outputs":[]},{"cell_type":"code","source":"ecg_data_ptb_xl.electrodes_problems.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:13:49.661581Z","iopub.execute_input":"2024-06-22T18:13:49.661877Z","iopub.status.idle":"2024-06-22T18:13:49.669328Z","shell.execute_reply.started":"2024-06-22T18:13:49.661851Z","shell.execute_reply":"2024-06-22T18:13:49.668209Z"},"trusted":true},"execution_count":116,"outputs":[{"execution_count":116,"output_type":"execute_result","data":{"text/plain":"Series([], Name: count, dtype: int64)"},"metadata":{}}]},{"cell_type":"code","source":"ecg_data_ptb_xl.to_csv(\"df_ptb_xl.csv\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# mimic 4","metadata":{}},{"cell_type":"code","source":"path = '/kaggle/input/ptb-xl-a-large-publicly-available2/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.3/'\n\necg_data = pd.read_csv(path + 'ptbxl_database.csv', index_col='ecg_id')\nscp_data = pd.read_csv(path + 'scp_statements.csv')\nscp_data[scp_data.diagnostic == 1].diagnostic_class.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:16:06.926188Z","iopub.execute_input":"2024-06-22T18:16:06.926573Z","iopub.status.idle":"2024-06-22T18:16:07.085974Z","shell.execute_reply.started":"2024-06-22T18:16:06.926535Z","shell.execute_reply":"2024-06-22T18:16:07.085063Z"},"trusted":true},"execution_count":117,"outputs":[{"execution_count":117,"output_type":"execute_result","data":{"text/plain":"diagnostic_class\nMI      14\nSTTC    13\nCD      11\nHYP      5\nNORM     1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"machine_measurements = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/mimic/machine_measurements.csv\", index_col=0)\nmachine_measurements.report_0.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:16:50.801467Z","iopub.execute_input":"2024-06-22T18:16:50.801874Z","iopub.status.idle":"2024-06-22T18:16:56.060334Z","shell.execute_reply.started":"2024-06-22T18:16:50.801838Z","shell.execute_reply":"2024-06-22T18:16:56.059382Z"},"trusted":true},"execution_count":118,"outputs":[{"name":"stderr","text":"/tmp/ipykernel_42/2419392448.py:1: DtypeWarning: Columns (16,17,18,19,20,21) have mixed types. Specify dtype option on import or set low_memory=False.\n  machine_measurements = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/mimic/machine_measurements.csv\", index_col=0)\n","output_type":"stream"},{"execution_count":118,"output_type":"execute_result","data":{"text/plain":"report_0\nSinus rhythm                                                                                                                          317278\nSinus rhythm.                                                                                                                          59739\nSinus bradycardia                                                                                                                      58924\nSinus tachycardia                                                                                                                      40528\nAtrial fibrillation                                                                                                                    31961\n                                                                                                                                       ...  \nSinus tachycardia with sinus arrhythmia with fusion complexes                                                                              1\nPossible atrial flutter with rapid ventricular response with frequent multifocal PVCs or aberrant ventricular conduction.                  1\nIrregular ectopic atrial tachycardia with PVCs.                                                                                            1\nSinus tachycardia with sinus arrhythmia with aberrantly conducted supraventricular complexes with borderline 1st degree A-V block.         1\nSinus rhythm with frequent PVCs with occasional PACs with borderline 1st degree A-V block.                                                 1\nName: count, Length: 1570, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"machine_measurements.report_1.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:16:59.574744Z","iopub.execute_input":"2024-06-22T18:16:59.575137Z","iopub.status.idle":"2024-06-22T18:16:59.682409Z","shell.execute_reply.started":"2024-06-22T18:16:59.575106Z","shell.execute_reply":"2024-06-22T18:16:59.681388Z"},"trusted":true},"execution_count":119,"outputs":[{"execution_count":119,"output_type":"execute_result","data":{"text/plain":"report_1\nLeft axis deviation                                                              62179\nProlonged QT interval                                                            30202\nLeftward axis                                                                    28239\nPoor R wave progression - probable normal variant                                22837\nRight bundle branch block                                                        18877\n                                                                                 ...  \nExtensive ST elevation, consider recent extensive infarction                         1\nLead(s) unsuitable for analysis: II III aVR aVL aVF V1 V2 V5 V6                      1\nLead(s) unsuitable for analysis: II III aVR aVL aVF V2 V5 V6                         1\nLead(s) unsuitable for analysis: II III aVR aVF V5                                   1\nSinus tachycardia with sinus arrhythmia with borderline 1st degree A-V block.        1\nName: count, Length: 2254, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"for i in ['report_0','report_1','report_2','report_3','report_4','report_5','report_6','report_7','report_8','report_9']:\n    machine_measurements[i] = machine_measurements[i].replace(to_replace ='[.]', value = '', regex = True).str.lower()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:17:07.591162Z","iopub.execute_input":"2024-06-22T18:17:07.592091Z","iopub.status.idle":"2024-06-22T18:17:13.972988Z","shell.execute_reply.started":"2024-06-22T18:17:07.592044Z","shell.execute_reply":"2024-06-22T18:17:13.972055Z"},"trusted":true},"execution_count":120,"outputs":[]},{"cell_type":"code","source":"machine_measurements = machine_measurements[machine_measurements.report_2 != \"normal ecg\"]\nmachine_measurements = machine_measurements[machine_measurements.report_2 != \"normal ecg except for rate\"]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:17:13.974757Z","iopub.execute_input":"2024-06-22T18:17:13.975125Z","iopub.status.idle":"2024-06-22T18:17:14.806241Z","shell.execute_reply.started":"2024-06-22T18:17:13.975091Z","shell.execute_reply":"2024-06-22T18:17:14.805261Z"},"trusted":true},"execution_count":121,"outputs":[]},{"cell_type":"code","source":"machine_measurements[machine_measurements.report_2 == \"normal ecg except for rate\"].report_9.value_counts()[:20]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:17:19.767223Z","iopub.execute_input":"2024-06-22T18:17:19.767582Z","iopub.status.idle":"2024-06-22T18:17:19.879540Z","shell.execute_reply.started":"2024-06-22T18:17:19.767545Z","shell.execute_reply":"2024-06-22T18:17:19.878664Z"},"trusted":true},"execution_count":122,"outputs":[{"execution_count":122,"output_type":"execute_result","data":{"text/plain":"Series([], Name: count, dtype: int64)"},"metadata":{}}]},{"cell_type":"code","source":"scp_data[(scp_data.rhythm == 1) | (scp_data.diagnostic == 1)][:2]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:17:26.497611Z","iopub.execute_input":"2024-06-22T18:17:26.498404Z","iopub.status.idle":"2024-06-22T18:17:26.515063Z","shell.execute_reply.started":"2024-06-22T18:17:26.498369Z","shell.execute_reply":"2024-06-22T18:17:26.514152Z"},"trusted":true},"execution_count":123,"outputs":[{"execution_count":123,"output_type":"execute_result","data":{"text/plain":"  Unnamed: 0                     description  diagnostic  form  rhythm  \\\n0        NDT  non-diagnostic T abnormalities         1.0   1.0     NaN   \n1       NST_         non-specific ST changes         1.0   1.0     NaN   \n\n  diagnostic_class diagnostic_subclass  \\\n0             STTC                STTC   \n1             STTC                NST_   \n\n                                  Statement Category  \\\n0                  other ST-T descriptive statements   \n1  Basic roots for coding ST-T changes and abnorm...   \n\n    SCP-ECG Statement Description  AHA code            aECG REFID CDISC Code  \\\n0  non-diagnostic T abnormalities       NaN                   NaN        NaN   \n1         non-specific ST changes     145.0  MDC_ECG_RHY_STHILOST        NaN   \n\n  DICOM Code  \n0        NaN  \n1        NaN  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>description</th>\n      <th>diagnostic</th>\n      <th>form</th>\n      <th>rhythm</th>\n      <th>diagnostic_class</th>\n      <th>diagnostic_subclass</th>\n      <th>Statement Category</th>\n      <th>SCP-ECG Statement Description</th>\n      <th>AHA code</th>\n      <th>aECG REFID</th>\n      <th>CDISC Code</th>\n      <th>DICOM Code</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>NDT</td>\n      <td>non-diagnostic T abnormalities</td>\n      <td>1.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>STTC</td>\n      <td>STTC</td>\n      <td>other ST-T descriptive statements</td>\n      <td>non-diagnostic T abnormalities</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>NST_</td>\n      <td>non-specific ST changes</td>\n      <td>1.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>STTC</td>\n      <td>NST_</td>\n      <td>Basic roots for coding ST-T changes and abnorm...</td>\n      <td>non-specific ST changes</td>\n      <td>145.0</td>\n      <td>MDC_ECG_RHY_STHILOST</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"machine_measurements = machine_measurements.dropna(subset=[\"report_0\"])\nfor i in machine_measurements.report_0.index:\n    if isinstance(machine_measurements.report_0[i], float):\n        print(machine_measurements.report_0[i])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:18:03.566680Z","iopub.execute_input":"2024-06-22T18:18:03.567758Z","iopub.status.idle":"2024-06-22T18:18:37.826962Z","shell.execute_reply.started":"2024-06-22T18:18:03.567709Z","shell.execute_reply":"2024-06-22T18:18:37.825865Z"},"trusted":true},"execution_count":124,"outputs":[]},{"cell_type":"code","source":"descript = list(scp_data[(scp_data.rhythm == 1)].description)\n#Unnamed = list(scp_data[(scp_data.rhythm == 1)][\"Unnamed: 0\"])\nscp_data_new = scp_data[(scp_data.diagnostic == 1)][[\"Unnamed: 0\",\"description\"]].copy()\nscp_data_new[\"machine_measurements\"] = [\"-\"]*len(scp_data_new)","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:18:39.367984Z","iopub.execute_input":"2024-06-22T18:18:39.368858Z","iopub.status.idle":"2024-06-22T18:18:39.376917Z","shell.execute_reply.started":"2024-06-22T18:18:39.368804Z","shell.execute_reply":"2024-06-22T18:18:39.375806Z"},"trusted":true},"execution_count":125,"outputs":[]},{"cell_type":"code","source":"def f_1(l_new,name):\n    pand  = pd.DataFrame({\"report\":[],\"report_1\":[],\"study_id\":[]})\n    for i in l_new:\n        df = machine_measurements[machine_measurements.report_1 == i].copy()\n        study_id =df.study_id\n        report=[name]* len(df.study_id)\n        report_1=[i]* len(df.study_id)\n        pand = pd.concat([\n            pand,\n        pd.DataFrame({\"report\":report,\"report_1\":report_1,\"study_id\":study_id})\n        ])\n    return pand\ndef func_poisk_name(osn,osn_1,iskl ):\n    report = \"report_1\"\n    report_1 = pd.DataFrame({\"index\" : machine_measurements[report].value_counts().to_frame().index ,\"counts\" : list(machine_measurements[report].value_counts())})\n    l_new = report_1[report_1[\"index\"].str.contains(osn)]\n    for i in osn_1:\n        l_new = l_new[l_new[\"index\"].str.contains(i)]\n    for i in iskl:\n        l_new = l_new[(l_new[\"index\"].str.contains(i))!=True]\n    l_new = list(l_new[:10][\"index\"])\n    return l_new","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:18:47.629900Z","iopub.execute_input":"2024-06-22T18:18:47.630610Z","iopub.status.idle":"2024-06-22T18:18:47.640579Z","shell.execute_reply.started":"2024-06-22T18:18:47.630575Z","shell.execute_reply":"2024-06-22T18:18:47.639692Z"},"trusted":true},"execution_count":126,"outputs":[]},{"cell_type":"code","source":"scp_data_new[\"machine_measurements\"] = [\"-\"]*len(scp_data_new)\nfor i in scp_data_new.index:\n    if len(func_poisk_name(scp_data_new.description[i],[],[] ))>0:\n        scp_data_new[\"machine_measurements\"][i] = func_poisk_name(scp_data_new.description[i],[],[] )","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:18:59.962512Z","iopub.execute_input":"2024-06-22T18:18:59.963128Z","iopub.status.idle":"2024-06-22T18:19:10.495977Z","shell.execute_reply.started":"2024-06-22T18:18:59.963093Z","shell.execute_reply":"2024-06-22T18:19:10.495048Z"},"trusted":true},"execution_count":128,"outputs":[{"name":"stderr","text":"/tmp/ipykernel_42/1696149271.py:16: UserWarning: This pattern is interpreted as a regular expression, and has match groups. To actually get the groups, use str.extract.\n  l_new = report_1[report_1[\"index\"].str.contains(osn)]\n/tmp/ipykernel_42/1696149271.py:16: UserWarning: This pattern is interpreted as a regular expression, and has match groups. To actually get the groups, use str.extract.\n  l_new = report_1[report_1[\"index\"].str.contains(osn)]\n","output_type":"stream"}]},{"cell_type":"code","source":"df_new_machine_measurements = pd.DataFrame({\"report\":[],\"report_1\":[],\"study_id\":[]})\nfor i in scp_data_new[scp_data_new[\"machine_measurements\"] != \"-\"].index:\n    jn = scp_data_new[scp_data_new[\"machine_measurements\"] != \"-\"].machine_measurements[i]\n    k = scp_data_new[scp_data_new[\"machine_measurements\"] != \"-\"][\"Unnamed: 0\"][i]\n    df_new_machine_measurements = pd.concat([df_new_machine_measurements,f_1(jn,k)])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:19:10.497588Z","iopub.execute_input":"2024-06-22T18:19:10.497962Z","iopub.status.idle":"2024-06-22T18:19:13.464821Z","shell.execute_reply.started":"2024-06-22T18:19:10.497926Z","shell.execute_reply":"2024-06-22T18:19:13.464060Z"},"trusted":true},"execution_count":129,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements.report.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:19:15.774891Z","iopub.execute_input":"2024-06-22T18:19:15.775285Z","iopub.status.idle":"2024-06-22T18:19:15.787802Z","shell.execute_reply.started":"2024-06-22T18:19:15.775245Z","shell.execute_reply":"2024-06-22T18:19:15.786901Z"},"trusted":true},"execution_count":130,"outputs":[{"execution_count":130,"output_type":"execute_result","data":{"text/plain":"report\nLAFB     19364\nLVH      14868\nRVH       1025\nIRBBB      573\nCRBBB      573\nLPFB       410\nCLBBB      406\nILBBB      406\nAMI          1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"markdown","source":"Поиск по ключевым словам ","metadata":{}},{"cell_type":"code","source":" df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"a-v block\",[\"1st\"],[])+func_poisk_name(\"a-v block\",[\"first\"],[]),\"1AVB\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:19:46.871402Z","iopub.execute_input":"2024-06-22T18:19:46.871773Z","iopub.status.idle":"2024-06-22T18:19:48.522243Z","shell.execute_reply.started":"2024-06-22T18:19:46.871740Z","shell.execute_reply":"2024-06-22T18:19:48.521493Z"},"trusted":true},"execution_count":131,"outputs":[]},{"cell_type":"code","source":" df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"a-v block\",[\"3\"],[])+func_poisk_name(\"a-v block\",[\"2\"],[]),\"2AVB\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:19:53.517761Z","iopub.execute_input":"2024-06-22T18:19:53.518139Z","iopub.status.idle":"2024-06-22T18:19:55.165275Z","shell.execute_reply.started":"2024-06-22T18:19:53.518106Z","shell.execute_reply":"2024-06-22T18:19:55.164180Z"},"trusted":true},"execution_count":132,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"myocard\",[\"infer\",\"lateral\"],[\"ischemia\"] ),\"ILMI\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:20:12.789900Z","iopub.execute_input":"2024-06-22T18:20:12.790730Z","iopub.status.idle":"2024-06-22T18:20:13.430037Z","shell.execute_reply.started":"2024-06-22T18:20:12.790698Z","shell.execute_reply":"2024-06-22T18:20:13.429227Z"},"trusted":true},"execution_count":133,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"myocard\",[\"anter\",\"lateral\"],[\"ischemia\"] ),\"ALMI\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:20:13.928519Z","iopub.execute_input":"2024-06-22T18:20:13.929168Z","iopub.status.idle":"2024-06-22T18:20:14.480088Z","shell.execute_reply.started":"2024-06-22T18:20:13.929133Z","shell.execute_reply":"2024-06-22T18:20:14.479285Z"},"trusted":true},"execution_count":134,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"wolf\",[],[] ),\"WPW\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:20:25.094886Z","iopub.execute_input":"2024-06-22T18:20:25.095277Z","iopub.status.idle":"2024-06-22T18:20:25.648534Z","shell.execute_reply.started":"2024-06-22T18:20:25.095244Z","shell.execute_reply":"2024-06-22T18:20:25.647737Z"},"trusted":true},"execution_count":135,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"ischemi\",[\"lateral\"],[\"infero\",\"antero\",\"myocardial\"] ),\"ISCLA\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:20:34.222871Z","iopub.execute_input":"2024-06-22T18:20:34.223265Z","iopub.status.idle":"2024-06-22T18:20:34.704910Z","shell.execute_reply.started":"2024-06-22T18:20:34.223232Z","shell.execute_reply":"2024-06-22T18:20:34.704123Z"},"trusted":true},"execution_count":136,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                          f_1(func_poisk_name(\"ischemi\",[\"infer\",\"lateral\"],[\"antero\",\"myocardial\"] ),\"ISCIL\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:20:43.662821Z","iopub.execute_input":"2024-06-22T18:20:43.663185Z","iopub.status.idle":"2024-06-22T18:20:43.956999Z","shell.execute_reply.started":"2024-06-22T18:20:43.663153Z","shell.execute_reply":"2024-06-22T18:20:43.956044Z"},"trusted":true},"execution_count":137,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                         #right bundle branch block\n                                          f_1(func_poisk_name(\"right bundle branch block\",[\"right\"],[] ),\"CRBBB\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:06.406939Z","iopub.execute_input":"2024-06-22T18:21:06.407305Z","iopub.status.idle":"2024-06-22T18:21:06.914853Z","shell.execute_reply.started":"2024-06-22T18:21:06.407277Z","shell.execute_reply":"2024-06-22T18:21:06.913857Z"},"trusted":true},"execution_count":138,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                         #right bundle branch block\n                                          f_1(func_poisk_name(\"left bundle branch block\",[],[\"incomplete\"]),\"CLBBB\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:13.822421Z","iopub.execute_input":"2024-06-22T18:21:13.822869Z","iopub.status.idle":"2024-06-22T18:21:14.233780Z","shell.execute_reply.started":"2024-06-22T18:21:13.822821Z","shell.execute_reply":"2024-06-22T18:21:14.233056Z"},"trusted":true},"execution_count":139,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                         #right bundle branch block\n                                          f_1(func_poisk_name(\"st\",[\"non\",\"changes\"],[\"-t\"]),\"NST_\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:19.736809Z","iopub.execute_input":"2024-06-22T18:21:19.737187Z","iopub.status.idle":"2024-06-22T18:21:20.833790Z","shell.execute_reply.started":"2024-06-22T18:21:19.737154Z","shell.execute_reply":"2024-06-22T18:21:20.833014Z"},"trusted":true},"execution_count":140,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements = pd.concat([df_new_machine_measurements,\n                                         #right bundle branch block\n                                          f_1(func_poisk_name(\" t \",[\"abnorm\"],[\" st-\",\"st\",\"specific\"]),\"NDT\")])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:27.518948Z","iopub.execute_input":"2024-06-22T18:21:27.519341Z","iopub.status.idle":"2024-06-22T18:21:28.617490Z","shell.execute_reply.started":"2024-06-22T18:21:27.519312Z","shell.execute_reply":"2024-06-22T18:21:28.616723Z"},"trusted":true},"execution_count":141,"outputs":[]},{"cell_type":"code","source":"func_poisk_name(\"subendocardial\",[],[] )","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:33.750143Z","iopub.execute_input":"2024-06-22T18:21:33.751033Z","iopub.status.idle":"2024-06-22T18:21:33.952680Z","shell.execute_reply.started":"2024-06-22T18:21:33.750990Z","shell.execute_reply":"2024-06-22T18:21:33.951660Z"},"trusted":true},"execution_count":142,"outputs":[{"execution_count":142,"output_type":"execute_result","data":{"text/plain":"[]"},"metadata":{}}]},{"cell_type":"code","source":"df_new_machine_measurements.report.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:55.579435Z","iopub.execute_input":"2024-06-22T18:21:55.579787Z","iopub.status.idle":"2024-06-22T18:21:55.597114Z","shell.execute_reply.started":"2024-06-22T18:21:55.579757Z","shell.execute_reply":"2024-06-22T18:21:55.596056Z"},"trusted":true},"execution_count":145,"outputs":[{"execution_count":145,"output_type":"execute_result","data":{"text/plain":"report\nCRBBB    19480\nLAFB     19364\nLVH      14868\nCLBBB    10606\n1AVB      4472\nNST_      3387\nNDT       1845\nRVH       1025\nIRBBB      573\nLPFB       410\nILBBB      406\nISCLA      310\n2AVB       211\nILMI        33\nWPW         17\nALMI        16\nAMI          1\nISCIL        1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"df_new_machine_measurements = df_new_machine_measurements.drop_duplicates()\nscp_data_new[\"Unnamed_len\"] = len(scp_data_new[\"Unnamed: 0\"])*[0] \nfor i in df_new_machine_measurements.report.value_counts().index:\n    k_0 = scp_data_new[scp_data_new[\"Unnamed: 0\"] == str(i)].index\n    scp_data_new.Unnamed_len[k_0] =  int(df_new_machine_measurements.report.value_counts()[str(i)])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:21:51.977488Z","iopub.execute_input":"2024-06-22T18:21:51.977869Z","iopub.status.idle":"2024-06-22T18:21:52.214478Z","shell.execute_reply.started":"2024-06-22T18:21:51.977840Z","shell.execute_reply":"2024-06-22T18:21:52.213550Z"},"trusted":true},"execution_count":144,"outputs":[]},{"cell_type":"code","source":"#df_new_machine_measurements.to_csv(\"report_study_df_mimic_ver1.csv\")\n#df_new_machine_measurements = pd.read_csv('/kaggle/input/electrocardiogram-database-for-arrhythmia-study/report_study_df_mimic_ver1.csv', index_col=0)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_new_machine_measurements.report_1.value_counts()[1:]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:22:24.958883Z","iopub.execute_input":"2024-06-22T18:22:24.959260Z","iopub.status.idle":"2024-06-22T18:22:24.976807Z","shell.execute_reply.started":"2024-06-22T18:22:24.959229Z","shell.execute_reply":"2024-06-22T18:22:24.975911Z"},"trusted":true},"execution_count":146,"outputs":[{"execution_count":146,"output_type":"execute_result","data":{"text/plain":"report_1\nleft bundle branch block                                                                         10198\nleft anterior fascicular block                                                                    9674\npossible left anterior fascicular block                                                           8798\nleft ventricular hypertrophy                                                                      7466\npossible left ventricular hypertrophy                                                             3559\n                                                                                                 ...  \nchanges in v2 are probably due to left ventricular hypertrophy but consider septal infarction        1\ninferior/lateral t wave changes suggest myocardial infarct                                           1\nanterolateral st-t changes suggest myocardial infarct                                                1\ninferior/lateral st-t changes suggest myocardial infarction                                          1\natrial flutter with 2:1 a-v block                                                                    1\nName: count, Length: 98, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"df_new_machine_measurements.report.value_counts()[1:17]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:22:31.454293Z","iopub.execute_input":"2024-06-22T18:22:31.454890Z","iopub.status.idle":"2024-06-22T18:22:31.472117Z","shell.execute_reply.started":"2024-06-22T18:22:31.454854Z","shell.execute_reply":"2024-06-22T18:22:31.471134Z"},"trusted":true},"execution_count":147,"outputs":[{"execution_count":147,"output_type":"execute_result","data":{"text/plain":"report\nLAFB     19364\nLVH      14868\nCLBBB    10606\n1AVB      4472\nNST_      3387\nNDT       1845\nRVH       1025\nIRBBB      573\nLPFB       410\nILBBB      406\nISCLA      310\n2AVB       211\nILMI        33\nWPW         17\nALMI        16\nAMI          1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"d_measurements = df_new_machine_measurements[df_new_machine_measurements.report == \"CRBBB\"][:2000]\nfor i in df_new_machine_measurements.report.value_counts()[2:17].index:\n    d_measurements = pd.concat([\n        d_measurements,\n        df_new_machine_measurements[df_new_machine_measurements.report == i][:2000],\n])\n","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:22:37.822345Z","iopub.execute_input":"2024-06-22T18:22:37.823180Z","iopub.status.idle":"2024-06-22T18:22:38.040296Z","shell.execute_reply.started":"2024-06-22T18:22:37.823134Z","shell.execute_reply":"2024-06-22T18:22:38.039218Z"},"trusted":true},"execution_count":148,"outputs":[]},{"cell_type":"code","source":"d_measurements.report.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:22:56.616277Z","iopub.execute_input":"2024-06-22T18:22:56.617031Z","iopub.status.idle":"2024-06-22T18:22:56.626321Z","shell.execute_reply.started":"2024-06-22T18:22:56.616982Z","shell.execute_reply":"2024-06-22T18:22:56.625234Z"},"trusted":true},"execution_count":150,"outputs":[{"execution_count":150,"output_type":"execute_result","data":{"text/plain":"report\nCRBBB    2000\nLVH      2000\nCLBBB    2000\n1AVB     2000\nNST_     2000\nNDT      1845\nRVH      1025\nIRBBB     573\nLPFB      410\nILBBB     406\nISCLA     310\n2AVB      211\nILMI       33\nWPW        17\nALMI       16\nAMI         1\nName: count, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"d_measurements","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:23:05.829656Z","iopub.execute_input":"2024-06-22T18:23:05.830045Z","iopub.status.idle":"2024-06-22T18:23:05.843291Z","shell.execute_reply.started":"2024-06-22T18:23:05.829991Z","shell.execute_reply":"2024-06-22T18:23:05.842303Z"},"trusted":true},"execution_count":151,"outputs":[{"execution_count":151,"output_type":"execute_result","data":{"text/plain":"         report                                           report_1    study_id\n10052926  CRBBB               incomplete right bundle branch block  43221168.0\n10113525  CRBBB               incomplete right bundle branch block  44969762.0\n10113525  CRBBB               incomplete right bundle branch block  44989745.0\n10126957  CRBBB               incomplete right bundle branch block  40137514.0\n10126957  CRBBB               incomplete right bundle branch block  45791599.0\n...         ...                                                ...         ...\n10423888   ALMI  anterolateral t wave changes suggest myocardia...  49405512.0\n13200333   ALMI  anterolateral t wave changes suggest myocardia...  48484702.0\n16043920   ALMI  anterolateral t wave changes suggest myocardia...  45089637.0\n10819535   ALMI  anterolateral st-t changes suggest myocardial ...  48122927.0\n17387174    AMI            consider anterior myocardial infarction  49666654.0\n\n[14847 rows x 3 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>report</th>\n      <th>report_1</th>\n      <th>study_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>10052926</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>43221168.0</td>\n    </tr>\n    <tr>\n      <th>10113525</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>44969762.0</td>\n    </tr>\n    <tr>\n      <th>10113525</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>44989745.0</td>\n    </tr>\n    <tr>\n      <th>10126957</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>40137514.0</td>\n    </tr>\n    <tr>\n      <th>10126957</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>45791599.0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>10423888</th>\n      <td>ALMI</td>\n      <td>anterolateral t wave changes suggest myocardia...</td>\n      <td>49405512.0</td>\n    </tr>\n    <tr>\n      <th>13200333</th>\n      <td>ALMI</td>\n      <td>anterolateral t wave changes suggest myocardia...</td>\n      <td>48484702.0</td>\n    </tr>\n    <tr>\n      <th>16043920</th>\n      <td>ALMI</td>\n      <td>anterolateral t wave changes suggest myocardia...</td>\n      <td>45089637.0</td>\n    </tr>\n    <tr>\n      <th>10819535</th>\n      <td>ALMI</td>\n      <td>anterolateral st-t changes suggest myocardial ...</td>\n      <td>48122927.0</td>\n    </tr>\n    <tr>\n      <th>17387174</th>\n      <td>AMI</td>\n      <td>consider anterior myocardial infarction</td>\n      <td>49666654.0</td>\n    </tr>\n  </tbody>\n</table>\n<p>14847 rows × 3 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"d_measurements[\"report_0\"] = len(d_measurements)*[\"-\"]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:23:25.719460Z","iopub.execute_input":"2024-06-22T18:23:25.720215Z","iopub.status.idle":"2024-06-22T18:23:25.725620Z","shell.execute_reply.started":"2024-06-22T18:23:25.720179Z","shell.execute_reply":"2024-06-22T18:23:25.724633Z"},"trusted":true},"execution_count":152,"outputs":[]},{"cell_type":"code","source":"report_0_0=[]\nfor i in d_measurements.study_id:\n    report_0_0.append(list(machine_measurements[machine_measurements.study_id == i].report_0)[0])","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:23:26.750038Z","iopub.execute_input":"2024-06-22T18:23:26.750868Z","iopub.status.idle":"2024-06-22T18:23:46.195470Z","shell.execute_reply.started":"2024-06-22T18:23:26.750833Z","shell.execute_reply":"2024-06-22T18:23:46.194460Z"},"trusted":true},"execution_count":153,"outputs":[]},{"cell_type":"code","source":"d_measurements[\"report_0\"] = report_0_0","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:23:46.197349Z","iopub.execute_input":"2024-06-22T18:23:46.197639Z","iopub.status.idle":"2024-06-22T18:23:46.203938Z","shell.execute_reply.started":"2024-06-22T18:23:46.197613Z","shell.execute_reply":"2024-06-22T18:23:46.202744Z"},"trusted":true},"execution_count":154,"outputs":[]},{"cell_type":"code","source":"def freport_0(name):\n    for j in [\"sinus rhythm\",\"sinus tachycardia\",\"sinus bradycardia\",\"atrial fibrillation\",\"sinus arrhythmia\",\"atrial flutter\" ]:\n        if j in str(name):\n            return j\n    return name\n\nreport_0_0 = []\nfor i in d_measurements.study_id:\n    name = list(d_measurements[d_measurements.study_id == i][\"report_0\"])[0]\n    report_0_0.append(freport_0(name))","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:23:46.205651Z","iopub.execute_input":"2024-06-22T18:23:46.206072Z","iopub.status.idle":"2024-06-22T18:23:51.317766Z","shell.execute_reply.started":"2024-06-22T18:23:46.206038Z","shell.execute_reply":"2024-06-22T18:23:51.316587Z"},"trusted":true},"execution_count":155,"outputs":[]},{"cell_type":"code","source":"d_measurements[:4]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:23:51.319850Z","iopub.execute_input":"2024-06-22T18:23:51.320187Z","iopub.status.idle":"2024-06-22T18:23:51.332186Z","shell.execute_reply.started":"2024-06-22T18:23:51.320157Z","shell.execute_reply":"2024-06-22T18:23:51.331170Z"},"trusted":true},"execution_count":156,"outputs":[{"execution_count":156,"output_type":"execute_result","data":{"text/plain":"         report                              report_1    study_id  \\\n10052926  CRBBB  incomplete right bundle branch block  43221168.0   \n10113525  CRBBB  incomplete right bundle branch block  44969762.0   \n10113525  CRBBB  incomplete right bundle branch block  44989745.0   \n10126957  CRBBB  incomplete right bundle branch block  40137514.0   \n\n                     report_0  \n10052926         sinus rhythm  \n10113525         sinus rhythm  \n10113525         sinus rhythm  \n10126957  atrial fibrillation  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>report</th>\n      <th>report_1</th>\n      <th>study_id</th>\n      <th>report_0</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>10052926</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>43221168.0</td>\n      <td>sinus rhythm</td>\n    </tr>\n    <tr>\n      <th>10113525</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>44969762.0</td>\n      <td>sinus rhythm</td>\n    </tr>\n    <tr>\n      <th>10113525</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>44989745.0</td>\n      <td>sinus rhythm</td>\n    </tr>\n    <tr>\n      <th>10126957</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>40137514.0</td>\n      <td>atrial fibrillation</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"markdown","source":"## read record - создание файла с путями для предыдущей таблицы","metadata":{}},{"cell_type":"code","source":"record_list = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/mimic/record_list.csv\", index_col=0)","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:24:48.089998Z","iopub.execute_input":"2024-06-22T18:24:48.090783Z","iopub.status.idle":"2024-06-22T18:24:49.938338Z","shell.execute_reply.started":"2024-06-22T18:24:48.090749Z","shell.execute_reply":"2024-06-22T18:24:49.937327Z"},"trusted":true},"execution_count":157,"outputs":[]},{"cell_type":"code","source":"path = []\nname_file = []\nfor i in d_measurements.study_id:\n    n=  list(record_list[record_list.study_id == i].path)[0].split(\"/\")\n    path.append(\"/\".join(n[:-1]))\n    name_file.append(\"/\".join(n[-1:]))","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:24:56.493454Z","iopub.execute_input":"2024-06-22T18:24:56.494196Z","iopub.status.idle":"2024-06-22T18:25:15.696512Z","shell.execute_reply.started":"2024-06-22T18:24:56.494161Z","shell.execute_reply":"2024-06-22T18:25:15.695756Z"},"trusted":true},"execution_count":158,"outputs":[]},{"cell_type":"code","source":"d_measurements[\"path\"] = path\nd_measurements[\"name_file\"] = name_file","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:25:15.698121Z","iopub.execute_input":"2024-06-22T18:25:15.698443Z","iopub.status.idle":"2024-06-22T18:25:15.705523Z","shell.execute_reply.started":"2024-06-22T18:25:15.698416Z","shell.execute_reply":"2024-06-22T18:25:15.704703Z"},"trusted":true},"execution_count":159,"outputs":[]},{"cell_type":"code","source":"d_measurements[:4]","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:25:15.706708Z","iopub.execute_input":"2024-06-22T18:25:15.707048Z","iopub.status.idle":"2024-06-22T18:25:15.721720Z","shell.execute_reply.started":"2024-06-22T18:25:15.706988Z","shell.execute_reply":"2024-06-22T18:25:15.720783Z"},"trusted":true},"execution_count":160,"outputs":[{"execution_count":160,"output_type":"execute_result","data":{"text/plain":"         report                              report_1    study_id  \\\n10052926  CRBBB  incomplete right bundle branch block  43221168.0   \n10113525  CRBBB  incomplete right bundle branch block  44969762.0   \n10113525  CRBBB  incomplete right bundle branch block  44989745.0   \n10126957  CRBBB  incomplete right bundle branch block  40137514.0   \n\n                     report_0                             path name_file  \n10052926         sinus rhythm  files/p1005/p10052926/s43221168  43221168  \n10113525         sinus rhythm  files/p1011/p10113525/s44969762  44969762  \n10113525         sinus rhythm  files/p1011/p10113525/s44989745  44989745  \n10126957  atrial fibrillation  files/p1012/p10126957/s40137514  40137514  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>report</th>\n      <th>report_1</th>\n      <th>study_id</th>\n      <th>report_0</th>\n      <th>path</th>\n      <th>name_file</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>10052926</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>43221168.0</td>\n      <td>sinus rhythm</td>\n      <td>files/p1005/p10052926/s43221168</td>\n      <td>43221168</td>\n    </tr>\n    <tr>\n      <th>10113525</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>44969762.0</td>\n      <td>sinus rhythm</td>\n      <td>files/p1011/p10113525/s44969762</td>\n      <td>44969762</td>\n    </tr>\n    <tr>\n      <th>10113525</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>44989745.0</td>\n      <td>sinus rhythm</td>\n      <td>files/p1011/p10113525/s44989745</td>\n      <td>44989745</td>\n    </tr>\n    <tr>\n      <th>10126957</th>\n      <td>CRBBB</td>\n      <td>incomplete right bundle branch block</td>\n      <td>40137514.0</td>\n      <td>atrial fibrillation</td>\n      <td>files/p1012/p10126957/s40137514</td>\n      <td>40137514</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"#d_measurements.to_csv(\"d_measurements.csv\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"record_list = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/mimic/record_list.csv\", index_col=0)\nd_measurements = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/d_measurements.csv\", index_col=0)\necg_df_HTV_mimic = pd.read_csv(\"/kaggle/input/electrocardiogram-database-for-arrhythmia-study/ecg_df_HTV_mimic.csv\", index_col=0)\nlen(d_measurements),len(ecg_df_HTV_mimic)","metadata":{"execution":{"iopub.status.busy":"2024-06-22T18:25:59.215759Z","iopub.execute_input":"2024-06-22T18:25:59.216792Z","iopub.status.idle":"2024-06-22T18:26:03.497938Z","shell.execute_reply.started":"2024-06-22T18:25:59.216719Z","shell.execute_reply":"2024-06-22T18:26:03.497033Z"},"trusted":true},"execution_count":162,"outputs":[{"execution_count":162,"output_type":"execute_result","data":{"text/plain":"(18811, 18811)"},"metadata":{}}]}]}